可能重复:
"位图太大而无法上传到纹理中"
我正在使用相机拍照,然后我将图片保存在SD卡上,然后使用
Bitmap bm = BitmapFactory.decodeFile(path);
要获得位图,那么
imageView.setImageBitmap(bm); 设置它.
但是当我把它放到我的视野中使用时
mFrameLayout.addView(imageView); 没有显示图像,我回来了 Bitmap to large to be uploaded into texture
位图是 1944 high, 2592 wide
有什么想法吗?
I am using a tablet, 10.1 inches, acer iconia, a500, running ics.
尝试这个
public static Bitmap decodeFile(File f,int WIDTH,int HIGHT){
try {
//Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(new FileInputStream(f),null,o);
//The new size we want to scale to
final int REQUIRED_WIDTH=WIDTH;
final int REQUIRED_HIGHT=HIGHT;
//Find the correct scale value. It should be the power of 2.
int scale=1;
while(o.outWidth/scale/2>=REQUIRED_WIDTH && o.outHeight/scale/2>=REQUIRED_HIGHT)
scale*=2;
//Decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize=scale;
return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
}
catch (FileNotFoundException e) {}
return null;
}
Run Code Online (Sandbox Code Playgroud)
这将根据您传递的宽度和高度缩放位图
| 归档时间: |
|
| 查看次数: |
4449 次 |
| 最近记录: |