[android] BitmapDrawable 더 이상 사용되지 않는 대안

드로어 블을 설정된 각도만큼 회전시키는 다음 코드가 있습니다.

    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);
    }

새로운 SDK는

BitmapDrawable(canvasBitmap); 

더 이상 사용되지 않습니다. 전혀 대안이 있습니까?

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



답변

대신 다음을 수행하십시오.

return new BitmapDrawable(context.getResources(), canvasBitmap);


답변

한 번 시도하십시오.

  1. 활동 중

    BitmapDrawable background = new BitmapDrawable(this.getResources(), blurImageBg);
    
  2. 조각에서

    BitmapDrawable background = new BitmapDrawable(getActivity(), blurImageBg);
    
  3. 어댑터 또는 기타

    BitmapDrawable background = new BitmapDrawable(context.getResources(), blurImageBg);
    


답변

다음에 대한 Kotlin 코드 BitmapDrawable:

var bitmapDrawable = BitmapDrawable(resources,bitmapObj)


답변