zoukankan      html  css  js  c++  java
  • 实现图片缩放

    private Bitmap resizeImage(Bitmap originalBitmap, int newWidth, int newHeight){
    int width = originalBitmap.getWidth();
    int height = originalBitmap.getHeight();
    //定义欲转换成的宽、高
    // int newWidth = 200;
    // int newHeight = 200;
    //计算宽、高缩放率
    float scanleWidth = (float)newWidth/width;
    float scanleHeight = (float)newHeight/height;
    //创建操作图片用的matrix对象 Matrix
    Matrix matrix = new Matrix();
    // 缩放图片动作
    matrix.postScale(scanleWidth,scanleHeight); //两个参数为宽度和高度的缩放
    //旋转图片 动作
    //matrix.postRotate(45);
    // 创建新的图片Bitmap
    Bitmap resizedBitmap = Bitmap.createBitmap(originalBitmap,0,0,width,height,matrix,true);
    return resizedBitmap;
    }
  • 相关阅读:
    2019.8.8 python day03
    2019.8.7 python进阶day02
    2019.8.6(python day01)
    2019.8.5
    2019.8.2
    2019.8.1
    2019.7.31
    2019.7.30
    面向对象进阶
    访问可见性问题和@property装饰器
  • 原文地址:https://www.cnblogs.com/to-creat/p/5186206.html
Copyright © 2011-2022 走看看