2016-04-26 12 views
1

私はテレビ用のAndroidアプリケーションを作成しています&画像形式の広告の種類を示すタブレットデバイス。大きなビットマップをAndroidでスムーズにループする方法

私はユニバーサル・画像・ローダーライブラリを使用してキャッシュに保存されていた method to load Bitmaps次使用してい

public static Bitmap getSampledBitmapFromFile(File file, int reqWidth, int reqHeight) { 

    // First decode with inJustDecodeBounds=true to check dimensions 
    final BitmapFactory.Options options = new BitmapFactory.Options(); 
    options.inJustDecodeBounds = true; 
    BitmapFactory.decodeFile(file.getPath(), options); 

    // Calculate inSampleSize 
    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); 

    // Decode bitmap with inSampleSize set 
    options.inJustDecodeBounds = false; 
    return BitmapFactory.decodeFile(file.getPath(), options); 
} 

これはロードBitmap方法です:

for(int i ==0; i<media.size() ; i++){ 
new AsyncTask<String, Void, Bitmap>() { 
     private final WeakReference<ImageView> imageViewReference = new WeakReference<ImageView>(campaignImg); 
     // Decode image in background. 
     @Override 
     protected Bitmap doInBackground(String... params) { 
      return Config.getSampledBitmapFromFile(ImageLoader.getInstance().getDiskCache().get(params[0]), 
        mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels); 
     } 
     // Once complete, see if ImageView is still around and set bitmap. 
     @Override 
     protected void onPostExecute(Bitmap bitmap) { 
      if (bitmap != null) { 
       final ImageView imageView = imageViewReference.get(); 
       if (imageView != null) { 
        imageView.setImageBitmap(bitmap); 
        animateImages(imageView, media.interval); 
       } 
      } 
     } 
    }.execute(media.imageUrl); 
} 

私の問題は、アプリケーションイメージです回転が滑らかでなく、変化している間に画像がちらつく。画像は10秒で変化しています。私のログキャットの言葉に従う:

D/dalvikvm: GC_FOR_ALLOC freed 11788K, 66% free 12375K/36295K, paused 19ms, total 19ms 
I/dalvikvm-heap: Grow heap (frag case) to 23.587MB for 12000016-byte allocation 
D/dalvikvm: GC_CONCURRENT freed 2K, 34% free 24091K/36295K, paused 12ms+5ms, total 43ms 
D/dalvikvm: WAIT_FOR_CONCURRENT_GC blocked 17ms 
D/dalvikvm: GC_FOR_ALLOC freed 5923K, 50% free 18241K/36295K, paused 59ms, total 60ms 
I/dalvikvm-heap: Grow heap (frag case) to 29.316MB for 12000016-byte allocation 
D/dalvikvm: GC_CONCURRENT freed 2K, 18% free 29957K/36295K, paused 13ms+6ms, total 50ms 
D/dalvikvm: WAIT_FOR_CONCURRENT_GC blocked 32ms 
D/dalvikvm: GC_FOR_ALLOC freed 11791K, 50% free 18241K/36295K, paused 22ms, total 22ms 
I/dalvikvm-heap: Grow heap (frag case) to 29.316MB for 12000016-byte allocation 
GC_FOR_ALLOC freed 2K, 18% free 29957K/36295K, paused 29ms, total 29ms 

私はメモリの使用量を減らすか、パフォーマンスを改善するために何ができるのですか?

+0

試してみてくださいhttp://square.github.io/picasso/ – DKV

答えて

1

ローカルフォルダのパスまたはサーバーのURL とパスを交換してくださいラーイの答えはキャッシュから画像をロードするためのUILを使用するように私をinspried。私はこれを先にしておくべきだったと思う。

これを覚えておけば、手動で処理する代わりに、画像のロード、キャッシュ、または表示にライブラリを使用することを常にお勧めします。私のプロジェクトで既にUILを使用していたので、次のように使用して終了しました。

ImageLoader.getInstance().displayImage(media.imageUrl, campaignImg, new SimpleImageLoadingListener() { 
     @Override 
     public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { 
      super.onLoadingComplete(imageUri, view, loadedImage); 
      animateImages(campaignImg, media.interval); 
     } 
    }); 
1

メモリ問題を回避するには、PicassoまたはGlideライブラリを使用してください。

Glide.with (context).load (path).asBitmap().into(imageView); 
関連する問題