gpt4 book ai didi

android - BitmapDrawable 已弃用的替代方案

转载 作者:IT老高 更新时间:2023-10-28 13:09:29 30 4
gpt4 key购买 nike

我有以下代码可以将可绘制对象旋转一定的度数。

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

关于android - BitmapDrawable 已弃用的替代方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9978884/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com