publicvoidload(Viewview){//图片太大会导致内存溢出//Bitmapbitmap=BitmapFactory.decodeResource(getResources(),R.drawable.big);//创建一个配置参数BitmapFactory.Optionsopts=newOptions();opts.inJustDecodeBounds=true;//不真实解析位图,只是解析位图的宽高信息Bitmapbitmap=BitmapFactory.decodeResource(getResources(),R.drawable.big,opts);intwidth=opts.outWidth;intheight=opts.outHeight;System.out.println("图片的宽度:"+width);System.out.println("图片的高度:"+height);intscale=1;//计算缩放的比例intscaleX=width/screenWidth;intscaleY=height/screenHeight;if(scaleX>scaleY&&scaleY>=1){scale=scaleX;}elseif(scaleX<scaleY&&scaleX>=1){scale=scaleY;}opts.inSampleSize=scale;opts.inJustDecodeBounds=false;//设置好了宽高后,真实解析位图bitmap=BitmapFactory.decodeResource(getResources(),R.drawable.big,opts);iv_show.setImageBitmap(bitmap);}