BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream( new FileInputStream(new File(path_image)), null, o); int w = o.outWidth; int h = o.outHeight; int scale = 1; while (true) { if (w / 2 <= mWidth_image || h / 2 <= mWidth_image) { break; } w /= 2; h /= 2; scale *= 2; } o.inSampleSize = scale; o.inJustDecodeBounds = false; newBitmap = BitmapFactory.decodeStream( new FileInputStream(new File(path_image)), null, o); 你可以参考一下,这个不会把图片加载到内存中,就可以获取宽和高。
public byte[] InputStreamToByte(InputStream iStrm) throws IOException { ByteArrayOutputStream bytestream = new ByteArrayOutputStream(); int ch; while ((ch = iStrm.read()) != -1) { bytestream.write(ch); Log.i("xpf", "as=one writed" + bytestream.size() + " 剩余" + (Filel - bytestream.size())); } byte imgdata[] = bytestream.toByteArray(); bytestream.close(); return imgdata; } s
BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream( new FileInputStream(new File(path_image)), null, o); int w = o.outWidth; int h = o.outHeight; int scale = 1; while (true) { if (w / 2 <= mWidth_image || h / 2 <= mWidth_image) { break; } w /= 2; h /= 2; scale *= 2; } o.inSampleSize = scale; o.inJustDecodeBounds = false; newBitmap = BitmapFactory.decodeStream( new FileInputStream(new File(path_image)), null, o);这种方式不会把图片加载到内存中吗,有何依据?
太笼统了 ,可以详细点儿不。比如一开始获得bitmap对象都会出现内存溢出
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(
new FileInputStream(new File(path_image)), null, o);
int w = o.outWidth;
int h = o.outHeight;
int scale = 1;
while (true) {
if (w / 2 <= mWidth_image || h / 2 <= mWidth_image) {
break;
}
w /= 2;
h /= 2;
scale *= 2;
}
o.inSampleSize = scale;
o.inJustDecodeBounds = false;
newBitmap = BitmapFactory.decodeStream(
new FileInputStream(new File(path_image)), null, o);
你可以参考一下,这个不会把图片加载到内存中,就可以获取宽和高。
ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
int ch;
while ((ch = iStrm.read()) != -1) {
bytestream.write(ch);
Log.i("xpf", "as=one writed" + bytestream.size() + " 剩余" + (Filel - bytestream.size()));
}
byte imgdata[] = bytestream.toByteArray();
bytestream.close();
return imgdata;
}
s
为什么我这 获取bitmap为空 第一次decodeStream时候就是空 文件确实在该路径下
为什么我这 获取bitmap为空 第一次decodeStream时候就是空 文件确实在该路径下
你要注意injusetdecodebounds的设置,确定为false才会真正的加载图片到内存。
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(
new FileInputStream(new File(path_image)), null, o);
int w = o.outWidth;
int h = o.outHeight;
int scale = 1;
while (true) {
if (w / 2 <= mWidth_image || h / 2 <= mWidth_image) {
break;
}
w /= 2;
h /= 2;
scale *= 2;
}
o.inSampleSize = scale;
o.inJustDecodeBounds = false;
newBitmap = BitmapFactory.decodeStream(
new FileInputStream(new File(path_image)), null, o);这种方式不会把图片加载到内存中吗,有何依据?