Deprecated BitmapDrawable Alternative

I have the following code that will rotate the selection by a given number 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

 BitmapDrawable(canvasBitmap); 

outdated. Any alternatives at all?

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

+83
android drawable
Apr 02 2018-12-12T00:
source share
3 answers

Do this instead:

 return new BitmapDrawable(context.getResources(), canvasBitmap); 
+187
Apr 2 2018-12-12T00:
source share

Kotlin Code for BitmapDrawable :

 var bitmapDrawable = BitmapDrawable(resources,bitmapObj) 
0
Feb 17 '19 at 13:07 on
source share

Try this one time.

  1. In Activity

     BitmapDrawable background = new BitmapDrawable(this.getResources(), blurImageBg); 
  2. In fragment

     BitmapDrawable background = new BitmapDrawable(getActivity(), blurImageBg); 
  3. In the adapter or in another

     BitmapDrawable background = new BitmapDrawable(context.getResources(), blurImageBg); 
0
Aug 30 '19 at 9:41
source share



All Articles