android Bitmap缩放

来源:互联网 发布:建筑扫描建模软件 编辑:程序博客网 时间:2024/06/05 15:42




   // 获得屏幕的宽高   int screenWidth = getWindow().getWindowManager().getDefaultDisplay().getWidth();   int screenHeight = getWindow().getWindowManager().getDefaultDisplay().getHeight();    // 加载Imageview和获得图片的信息    final ImageView imageView = (ImageView) findViewById(R.id.imgView);    final Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.a);   int bitmapWidth = bitmap.getWidth();   int bitmapHeight = bitmap.getHeight();    // 计算缩放比,因为如果图片的尺寸超过屏幕,那么就会自动匹配到屏幕的尺寸去显示。    float scaleX = screenWidth / (float) bitmapWidth;    float scaleY = screenHeight / (float) bitmapHeight;    float  baseScale = Math.min(scaleX, scaleY);// 获得缩放比例最大的那个缩放比,即scaleX和scaleY中小的那个    final Matrix matrix = new Matrix();    matrix.setScale(baseScale, baseScale);       Bitmap bitmap2 = Bitmap.createBitmap(bitmap, 0, 0, bitmapWidth, bitmapHeight, matrix, false);    imageView.setImageBitmap(bitmap2);final Matrix matrix = new Matrix();    int bitmapWidth = bitmap[i].getWidth();    matrix.setScale(1/baseScale, 1/baseScale );    imageView.setImageMatrix(matrix);


0 0
原创粉丝点击