2014-06-20 187 views
0

我做了一個android應用程序,在一個活動中我有一個imageView,我想使用imageLoader向它顯示圖像,我已經使用了很多次imageloader ,但我得到了這種類型的錯誤圖片不能被解碼,我的代碼如下,請大家幫幫我吧, 代碼圖像未使用android中的通用圖像加載器加載

iv_profile = (ImageView) findViewById(R.id.iv_profile); 
imageLoader = ImageLoader.getInstance(); 
     imageLoader.init(ImageLoaderConfiguration.createDefault(HomeActivity.this)); 

     options = new DisplayImageOptions.Builder().cacheOnDisc(true).showStubImage(R.drawable.noimage).showImageOnFail(R.drawable.noimage).build(); 
String img = "http://tp.epagestore.in/" + Pref.getValue(HomeActivity.this, Const.PREF_PHOTO, ""); 
    imageLoader.displayImage(img, iv_profile, options); 
+0

看到這個問題https://github.com/nostra13/Android-Universal-Image-Loader/issues/541 –

+0

@ QadirHussain - 我已經通過它...只有無用的評論der ..:! – jigar

回答

0

請嘗試以下代碼,是很適合我。

在oncreate中初始化imageloader類。

you can change the config param if you want.

imageLoader = ImageLoader.getInstance(); 
      options = new DisplayImageOptions.Builder().showImageForEmptyUri(R.drawable.ic_empty) 
       .showImageOnFail(R.drawable.appicon_).resetViewBeforeLoading(true).cacheOnDisc(true) 
       .imageScaleType(ImageScaleType.EXACTLY).bitmapConfig(Bitmap.Config.RGB_565).considerExifParams(true) 
       .displayer(new FadeInBitmapDisplayer(300)).build(); 

     File cacheDir = StorageUtils.getCacheDirectory(mContext); 
     ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(mContext) 
       .memoryCacheExtraOptions(480, 800) 
       // default = device screen dimensions 
       .discCacheExtraOptions(480, 800, CompressFormat.JPEG, 75, null) 
       // .taskExecutor(AsyncTask.THREAD_POOL_EXECUTOR) 
       // .taskExecutorForCachedImages(AsyncTask.THREAD_POOL_EXECUTOR).threadPoolSize(3) 
       // default 
       .threadPriority(Thread.NORM_PRIORITY - 1) 
       // default 
       .tasksProcessingOrder(QueueProcessingType.FIFO) 
       // default 
       .denyCacheImageMultipleSizesInMemory().memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024)) 
       // default 
       .memoryCacheSize(2 * 1024 * 1024).discCache(new UnlimitedDiscCache(cacheDir)) 
       // default 
       .discCacheSize(50 * 1024 * 1024).discCacheFileCount(100) 
       .discCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default 
       .imageDownloader(new BaseImageDownloader(mContext)) // default 
       .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default 
       .build(); 
     if (imageLoader.isInited()) { 

     } else { 
      imageLoader.init(config); 
     } 

加載圖像鑑於

 imageLoader.displayImage(url, img, options, new ImageLoadingListener() { 
     @Override 
     public void onLoadingStarted(String imageUri, View view) { 

     } 

     @Override 
     public void onLoadingFailed(String imageUri, View view, FailReason failReason) { 


     } 

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

     } 

     @Override 
     public void onLoadingCancelled(String imageUri, View view) { 

     } 

    }); 
+0

同樣的問題在那裏...在logcat它給我錯誤**「解碼器返回false」** – jigar

+0

什麼是第二個參數「img」是? – jigar

+0

Img是圖像從url加載的圖像視圖。 –

相關問題