0

Lazy-List私はこのコードと私の画像ストアを次の名前のフォルダーに使用しますLazyList

ImageLoader imageLoader=new ImageLoader(context); imageLoader.DisplayImage(url, imageView);

しかし、Universal-Image-Loader私はこれを使用します

 ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())    
            .build();
    ImageLoader.getInstance().init(config);
    img = (ImageView) this.findViewById(R.id.test_id);
    ImageLoader imageLoader = ImageLoader.getInstance();
    imageLoader.displayImage(URL.RECIPE_IMG_URL,img);

.diskCache(new UnlimitedDiscCache(new File("myFolder")))しかし、毎回インターネットを使用して画像を取得し、画像を追加するフォルダーに画像を保存しませんでしたconfig が、何も保存しませんでしたmyFolder。何かアイデアはありますか?

4

2 に答える 2

5

画像を保存する必要がありますonLoadingComplete

これを試してください。変数onLoadingCompleteに保存する必要がありますbitmapbitmap

imageLoader.getInstance().displayImage(imagePath, imageView, options, new SimpleImageLoadingListener() {
        @Override
        public void onLoadingStarted(String imageUri, View view) {
            spinner.setVisibility(View.VISIBLE);
        }

        @Override
        public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
            String message = null;
            switch (failReason.getType()) {
            case IO_ERROR:
                message = "Input/Output error";
                break;
            case DECODING_ERROR:
                message = "Image can't be decoded";
                break;
            case NETWORK_DENIED:
                message = "Downloads are denied";
                break;
            case OUT_OF_MEMORY:
                message = "Out Of Memory error";
                break;
            case UNKNOWN:
                message = "Unknown error";
                break;
            }


        }

        @Override
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {

            showedImgae = loadedImage;

        }
    });

今すぐ保存ボタンをクリックしてください/それを保存したい場合Bitmap/これImageSDCard 使用するには

 public void downloadImage(){

    String root = Environment.getExternalStorageDirectory().toString();
    File myDir = new File(root + "/DCIM/youfoldername");    
    myDir.mkdirs();
    Random generator = new Random();
    int n = 10000;
    n = generator.nextInt(n);
    String fname = "imagename-"+ n +".jpg";
    File file = new File (myDir, fname);
    if (file.exists ()) file.delete (); 
    try {
        FileOutputStream out = new FileOutputStream(file);
        showedImgae.compress(Bitmap.CompressFormat.JPEG, 100, out);
        Toast.makeText(MyActivity.this, "Image Saved", Toast.LENGTH_SHORT).show();
        out.flush();
        out.close();

    } catch (Exception e) {
        e.printStackTrace();
    }

    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    Uri contentUri = Uri.fromFile(file);
    mediaScanIntent.setData(contentUri);
    getApplicationContext().sendBroadcast(mediaScanIntent);
}

それがあなたを助けることを願っています..

于 2014-08-18T17:56:40.597 に答える
4

私は自分の答えを見つけました。デフォルトではキャッシュは無効になっており、追加DisplayImageOptionsする必要がありますImageLoaderConfiguration

そして、ここにコードがあります

   DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .build();

        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
                .defaultDisplayImageOptions(defaultOptions)
                .build();
于 2014-08-19T05:01:59.833 に答える