android - 缩放位图效率

标签 android bitmap drawable

我想知道这两种方式中哪一种在内存或速度方面更有效。

第一种方式 - BitmapFactory.decodeResource

    Bitmap loadedBitmap = BitmapFactory.decodeResource(this.getResources(), R.drawable.big_image);
    Bitmap scaledBitmap = loadedBitmap.createScaledBitmap(loadedBitmap, 1920, 1080, false);

第二种方式 - (BitmapDrawable)getResources().getDrawable()

    Bitmap loadedBitmap = ((BitmapDrawable)getResources().getDrawable(R.drawable.big_image)).getBitmap();
    Bitmap scaledBitmap = loadedBitmap.createScaledBitmap(loadedBitmap, 1920, 1080, false);

最佳答案

第一种方法更好。

 Bitmap loadedBitmap = BitmapFactory.decodeResource(this.getResources(), R.drawable.big_image);
 Bitmap scaledBitmap = loadedBitmap.createScaledBitmap(loadedBitmap, 1920, 1080, false);

关于android - 缩放位图效率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34541153/

相关文章:

java - 如何在收到短信时发送回复短信?

android - 为什么在 Android Activity 中使用 LocationManager 单例不好?

android - android区域总是矩形区域还是可能是多边形或弯曲的?

c# - ZXing-Core BitMatrix转BitMap

android - 我不希望 Android 自动调整位图的大小

java - Android:如何将可绘制资源附加到电子邮件?

android - setBackground 与 setBackgroundDrawable (Android)

java - 升级 Android Studio NDK : CMAKE_C_COMPILER and CMAKE_CXX_COMPILER not set 后出错

android - BitmapFacotry.decodeByteArray 为有效图像的字节数组返回 null

delphi - Firemonkey PNG 转位图