public Bitmap decodebitmap(Context context, int imageid) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;// 如果值设为true,那么将不返回实际的bitmap,也不给其分配内存空间,这样就避免了内存溢出。
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),
imageid, options);
if (bitmap == null) {
Toast.makeText(context, "bitmap为空", 2).show();//这里能出来,是因为options.inJustDecodeBounds = true;
}
int realwidth = options.outWidth;
int realheight = options.outHeight;
System.out.println("图片真实高度" + realheight + "宽度" + realwidth);
// 计算缩放。
int scal = (int) ((realheight > realwidth ? realwidth : realheight) / 100);
if (scal <= 0) {
scal = 1;
}
options.inSampleSize = scal;
options.inJustDecodeBounds = false;
bitmap = BitmapFactory.decodeResource(context.getResources(), imageid,
op