80,472
社区成员




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