位图变大 [英] Bitmap to large
本文介绍了位图变大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能的重复:
位图太大而无法上传到纹理中"
我正在使用相机拍照,然后将图片保存在 sdcard 上,然后使用
I am taking a picture using the camera, then I am saving the picture on the sdcard, then using
Bitmap bm = BitmapFactory.decodeFile(path);
要获取位图,然后
imageView.setImageBitmap(bm);
设置它.
但是当我使用
mFrameLayout.addView(imageView);
没有图像显示,我又回来了 Bitmap 要上传到纹理中
mFrameLayout.addView(imageView);
no image is displayed and I get back Bitmap to large to be uploaded into texture
位图是1944高,2592宽
有什么想法吗?
我使用的是平板电脑,10.1 英寸,acer iconia,a500,运行 ics.
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;
}
这将根据您通过的宽度和高度缩放位图
this will scale bitmap as per width and height you pass
这篇关于位图变大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文