1.代码
Bitmap b = BitmapFactory.decodeResource(getResources() , R.drawable.a);ImageView cbt = (ImageView) findViewById(R.id.btmp1);cbt.setImageBitmap(b);Log.i("mydate" , b.getWidth() + " " + b.getHeight()); //ImageView cbtwdf = (ImageView) findViewById(R.id.btmp2);//对图片进行裁剪Bitmap bwdf = Bitmap.createBitmap(b , b.getWidth()/2 , b.getHeight()/2 , b.getWidth()/2 , b.getHeight()/2);cbtwdf.setImageBitmap(bwdf);Log.i("mydate" , bwdf.getWidth() + " " + bwdf.getHeight()); ////如果想要对裁剪后的图片进行缩放Matrix matrix = new Matrix();float wscale = (b.getWidth() / (b.getWidth()/2)) ; //如果裁剪后的图片要放大则乘以这个比值float hscale = (b.getHeight() / (b.getHeight()/2)) ;matrix.postScale(wscale , hscale);Bitmap bscale = Bitmap.createBitmap(b , b.getWidth()/2 , b.getHeight()/2 , b.getWidth()/2 , b.getHeight()/2 , matrix , true);ImageView cbtscale = (ImageView) findViewById(R.id.btmp3);cbtscale.setImageBitmap(bscale);Log.i("mydate" , bscale.getWidth() + " " + bscale.getHeight()); //
2.显示:
3.打印如下:
mydate: 1536 1536
mydate: 768 768
mydate: 1536 1536
mydate: 768 768
mydate: 1536 1536