Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BitmapDrawable deprecated alternative

I have the following code that will rotate a drawable by a set amount of degrees.

    public Drawable rotateDrawable(float angle, Context context)     {       Bitmap arrowBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.generic2rb);        // Create blank bitmap of equal size       Bitmap canvasBitmap = arrowBitmap.copy(Bitmap.Config.ARGB_8888, true);       canvasBitmap.eraseColor(0x00000000);        // Create canvas       Canvas canvas = new Canvas(canvasBitmap);        // Create rotation matrix       Matrix rotateMatrix = new Matrix();       rotateMatrix.setRotate(angle, canvas.getWidth()/2, canvas.getHeight()/2);        //Draw bitmap onto canvas using matrix       canvas.drawBitmap(arrowBitmap, rotateMatrix, null);        return new BitmapDrawable(canvasBitmap);      } 

The new SDK says that the

BitmapDrawable(canvasBitmap);  

is deprecated. Any alternatives at all?

http://developer.android.com/reference/android/graphics/drawable/BitmapDrawable.html

like image 618
Lee Armstrong Avatar asked Apr 02 '12 15:04

Lee Armstrong


1 Answers

Do this instead:

return new BitmapDrawable(context.getResources(), canvasBitmap); 
like image 91
onit Avatar answered Sep 23 '22 09:09

onit