0

I've caught a code example to pinch and zoom an image. The works ok. The problem is when I implement this code in my app. I have an OutOfMemoryError here:

view.setImageResource (R.drawable.planometro);

To solve this problem I found this code:

public Drawable getAssetImage (String filename) throws IOException {

    AssetManager assets = getResources () getAssets ().; 
    InputStream buffer = new BufferedInputStream ((assets.open ("drawable /" + filename +)) "png."); 
    Bitmap bitmap = BitmapFactory.decodeStream (buffer); 
    return new BitmapDrawable (getResources (), bitmap); 
 } 

The problem is that this code is to return an int, not a drawable. How I can fix my error?

Thanks

user3231711
  • 89
  • 3
  • 9

2 Answers2

0

try this

try {
   Bitmap bitmap=((BitmapDrawable)activity.getResources().getDrawable(R.drawable.matches_placeholder_upcoming2x)).getBitmap();
   Drawable drawable = new BitmapDrawable(activity.getResources(),bitmap);
   liveMatchHeaderContainer.setBackgroundDrawable(drawable);    

} catch (OutOfMemoryError E) {
    E.printStackTrace();
}
NagarjunaReddy
  • 8,621
  • 10
  • 63
  • 98
0

This worked for me, try it out:

        ImageView image = (ImageView) findViewById(R.id.img);
        try {
            Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
                    R.drawable.ic_launcher);
//          Drawable d = new BitmapDrawable(getResources(), bitmap);
            image.setBackgroundResource(R.drawable.ic_launcher);

        } catch (OutOfMemoryError E) {
            E.printStackTrace();
        }
Gabriela Radu
  • 757
  • 2
  • 12
  • 33