我正在尝试提高位图的效率。 目前,我有使用纹理视图创建的位图对象,
Bitmap bitmap = new AspectRatioTextureView(getActivity());
在那之后,我需要减小此位图的内存分配大小。为此,Google Developer's doc中有一个参考。为此,我们可以使用BitmapFactory
API。但是在BitmapFactory
中,我们可以使用Android资源文件夹加载图像。但是我在Android资源文件夹中没有图像。我只有一个位图图像对象。
public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,
int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resId, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, resId, options);
}
我需要使用我的Bitmap对象并减小其内存分配大小。但是没有任何指导。请给我一些帮助。感谢您的宝贵时间。