我有一个资源图像。如果我在没有实际解码的情况下读取它的维度,一切都很好(即使要求使用rgb565)。如果我解码成rgb565颜色格式的android api为我提供了两倍的尺寸太宽太高。
这是android中的一个bug吗?
private static Bitmap decodeBitmapAsRGB565( Resources res, int resId ) {
BitmapFactory.Options opt = new BitmapFactory.Options();
int origW, origH;
opt.inJustDecodeBounds= true; // don't decode contents, just get the dimensions
{
// Get original picture's dimensions
//
BitmapFactory.decodeResource( res, resId, opt );
Log.v("", String.format("***Original: %d x %d", opt.outWidth, opt.outHeight)); // 1532x2048
origW= opt.outWidth;
origH= opt.outHeight;
opt.inPreferredConfig= Bitmap.Config.RGB_565;
BitmapFactory.decodeResource( res, resId, opt );
Log.v("", String.format("***RGB565: %d x %d", opt.outWidth, opt.outHeight)); // 1532x2048
}
opt.inJustDecodeBounds= false;
opt.inPreferredConfig= Bitmap.Config.RGB_565; // needed for 'EFFECT_REDEYES'
final Bitmap bmp= BitmapFactory.decodeResource( res, resId, opt );
// Check that we got the size of the original
//
int w= bmp.getWidth();
int h= bmp.getHeight();
if ((w!=origW) || (h!=origH)) {
String s; Log.wtf("", s= String.format("Bitmap dimensions screwed: (%d,%d) vs. (%d,%d)", w,h, origW,origH));
throw new RuntimeException(s);
}
return bmp;
}
1条答案
按热度按时间p8h8hvxi1#
Resources
根据设备的屏幕密度进行缩放。如果您想避免扩展,可以将资源放在drawable-nodpi
目录。