zoukankan      html  css  js  c++  java
  • Android 等比例缩放图片

    // 缩放图片
    public static Bitmap zoomImg(String img, int newWidth ,int newHeight){
    // 图片源
       Bitmap bm = BitmapFactory.decodeFile(img);
       if(null!=bm){
        return zoomImg(bm,newWidth,newHeight);
       }
       return null;
    }
    
    public static Bitmap zoomImg(Context context,String img, int newWidth ,int newHeight){
    // 图片源
    try {
    Bitmap bm = BitmapFactory.decodeStream(context.getAssets()
    .open(img));
    if (null != bm) {
    return zoomImg(bm, newWidth, newHeight);
    }
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    return null;
    }
    // 缩放图片
    public static Bitmap zoomImg(Bitmap bm, int newWidth ,int newHeight){
       // 获得图片的宽高
       int width = bm.getWidth();
       int height = bm.getHeight();
       // 计算缩放比例
       float scaleWidth = ((float) newWidth) / width;
       float scaleHeight = ((float) newHeight) / height;
       // 取得想要缩放的matrix参数
       Matrix matrix = new Matrix();
       matrix.postScale(scaleWidth, scaleHeight);
       // 得到新的图片
       Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);
        return newbm;
    }
  • 相关阅读:
    语法树,短语,直接短语,句柄2.0
    语法树,短语,直接短语,句柄
    2.理解文法和语文
    编译原理的学习 No.1
    第一次个人编程作业
    Arduboy基本操作(二)
    Arduboy基本用法(一)
    物理存储管理实训题
    创建和管理用户作业
    PL/SQL语言基础
  • 原文地址:https://www.cnblogs.com/zhujiabin/p/5891365.html
Copyright © 2011-2022 走看看