BitmapDrawable德precated替代 [英] BitmapDrawable deprecated alternative

查看:422
本文介绍了BitmapDrawable德precated替代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code将由度一组量旋转绘制。

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

新的SDK说,

The new SDK says that the

BitmapDrawable(canvasBitmap); 

是pcated德$ P $。在所有其它方法吗?

is deprecated. Any alternatives at all?

<一个href="http://developer.android.com/reference/android/graphics/drawable/BitmapDrawable.html">http://developer.android.com/reference/android/graphics/drawable/BitmapDrawable.html

推荐答案

做到这一点,而不是:

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

另外的Java德precates东西所有的时间,你仍然可以使用它。我不知道,如果谷歌使用的是相同的理念,但如果它不破,则不需要进行修复。

Also Java deprecates stuff all the time and you can still use it. I'm not sure if Google is using the same philosophy, but if it isn't broken, you don't need to fix it.

这篇关于BitmapDrawable德precated替代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆