加载的超高分辨率内存大于手机分配给应用的内存,会造 oom。
要对图片进行压缩
image = (ImageView) findViewById(R.id.imag);
BitmapFactory.Options options =new Options();
options.inJustDecodeBounds = true;
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.beautiful,options);
/** 获取图片的分辨率
*
* **/
int bit_sclax = options.outWidth;
int bit_sclay = options.outHeight;
Log.i("bit","图片宽:--"+bit_sclax+"----图片高:--"+bit_sclay);
WindowManager window = (WindowManager) getSystemService(WINDOW_SERVICE);
/** 获取手机的屏幕分辨率 **/
int sclax = window.getDefaultDisplay().getWidth();
int sclay = window.getDefaultDisplay().getHeight();
Log.i("bit",":--"+sclax+"----手机:--"+sclay);
int sclae=1;
int a = bit_sclax/sclax;
int b = bit_sclay/sclay;
if(a>b&&a>sclae){
sclae = a;
}
options.inSampleSize = sclae;
options.inJustDecodeBounds = false;
Bitmap bit = BitmapFactory.decodeResource(getResources(), R.drawable.beautiful, options);
image.setImageBitmap(bit);
}