//使用Bitmap加Matrix来缩放
    public static Drawable resizeImage(Bitmap bitmap, int w, int h)
    
        Bitmap BitmapOrg = bitmap; 
        int width = BitmapOrg.getWidth(); 
        int height = BitmapOrg.getHeight(); 
        int newWidth = w; 
        int newHeight = h; 
 
        float scaleWidth = ((float) newWidth) / width; 
        float scaleHeight = ((float) newHeight) / height; 
 
        Matrix matrix = new Matrix(); 
        matrix.postScale(scaleWidth, scaleHeight); 
        // if you want to rotate the Bitmap  
        // matrix.postRotate(45);  
        Bitmap resizedBitmap = Bitmap.createBitmap(BitmapOrg, 0, 0, width, 
                        height, matrix, true); 
        return new BitmapDrawable(resizedBitmap); 
    }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//使用BitmapFactory.Options的inSampleSize参数来缩放
    public static Drawable resizeImage2(String path,
            int width,int height)
    {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;//不加载bitmap到内存中
        BitmapFactory.decodeFile(path,options);
        int outWidth = options.outWidth;
        int outHeight = options.outHeight;
        options.inDither = false;
        options.inPreferredConfig = Bitmap.Config.ARGB_8888;
        options.inSampleSize = 1;
         
        if (outWidth != 0 && outHeight != 0 && width != 0 && height != 0)
        {
            int sampleSize=(outWidth/width+outHeight/height)/2;
            Log.d(tag, "sampleSize = " + sampleSize);
            options.inSampleSize = sampleSize;
        }
     
        options.inJustDecodeBounds = false;
        return new BitmapDrawable(BitmapFactory.decodeFile(path, options));    
    }

推推族,免费得门票,游景区:www.tuituizu.com

结伴旅游,一个免费的交友网站:www.jieberu.com

Android图片缩放 指定尺寸的更多相关文章

  1. android图片缩放平移

    <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android=" ...

  2. Android图片缩放方法

    安卓开发中应用到图片的处理时候,我们通常会怎么缩放操作呢,来看下面的两种做法: 方法1:按固定比例进行缩放 在开发一些软件,如新闻客户端,很多时候要显示图片的缩略图,由于手机屏幕限制,一般情况下,我们 ...

  3. ASP.NET将原始图片按照指定尺寸等比例缩放显示图片

    网站上可能会有很多图片,比如产品图片等,而且他们可能大小不一,宽度和高度也不一定一样,有的很大有的很小.如果放在一张网页上,可能会破坏版面,但是如果强制让他们按照指定的宽度和高度显示,因为比例不同还会 ...

  4. Android 图片缩放

    以下演示将一个ImageView的高度设置为两倍: 布局文件main.xml <?xml version="1.0" encoding="utf-8"?& ...

  5. Delphi XE5 for android 图片缩放和拖动处理

    首先,需要分辨手势的类型. 有两种类型的手势: 一是标准手势(Standard Gestures): 在Windows,android上,标准手势都是用一个手指. 在Mac OS X and iOS上 ...

  6. android 图片缩放抗锯齿

    之前用的时候只设置了antialias属性,其实要设置两个flag才行 paint.setFlags(Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG); ...

  7. Andorid-如何为你的Android应用缩放图片

    很难为你的应用程序得到正确的图像缩放吗?是你的图片过大,造成内存问题?还是图片不正确缩放造成不良用户体验的结果?为了寻求一个好的解决方案,我们咨询了Andreas Agvard(索尼爱立信软件部门), ...

  8. Android 图片的缩放与旋转

    本文实现Android中的图片的缩放效果 首先设计布局: <LinearLayout xmlns:android="http://schemas.android.com/apk/res ...

  9. Android图片采样缩放

    为什么要对Android中的图片进行采样缩放呢? 是为了更加高效的加载Bitmap.假设通过imageView来显示图片,很多时候ImageView并没有图片的原始尺寸那么大,这时候把整张图片加载进来 ...

随机推荐

  1. 关于Vue的一些事

    Vue的官方网站 https://cn.vuejs.org/ Vue中的一些重点 router Vuex 知其然,后知其所以然 这是一篇Vue的源码解读 http://hcysun.me/2017/0 ...

  2. spring boot-11.全局捕获异常

    1.在Spring boot 中如果发生错误,浏览器访问会默认跳转到Whitelabel Error Page 这个错误页面,如果是客户端访问的话返回JSON格式的错误数据,说明spring boot ...

  3. Linux下面MariaDB 管理命令基础使用

    MariaDB 是 MySQL 的一个分,由于某些原因,使之取代了Mysql成为了 RHEL/CentOS 7 的默认数据库.针对数据库的操作我们经常做的操作就是增删查改,接下来就介绍下 MariaD ...

  4. @OneToMany 一对多 通过表之间的链接

    https://blog.csdn.net/qq_38157516/article/details/80146547 一对多 一个人对多张卡,但是一张卡只能对应一个人,典型的一对多关系,下面就用One ...

  5. 插入数据库失败([Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version)

    报错信息如下: , ) 原因,read是数据库的关键字, 牢记,如果一个词是数据库的关键字,那么在写数据库语句的时候,这个词一定是蓝色的(关键字颜色)!!

  6. python-day1(学前了解)

    Markdown基本语法 各级标题 # 一级标题 ## 二级标题 ### 三级标题 #### 四级标题 ##### 五级标题 加粗 **加粗文本** 斜体 *我斜了* 高亮 ==我高亮了== 上标 2 ...

  7. Jquery复习(七)之尺寸

    jQuery 尺寸 方法 jQuery 提供多个处理尺寸的重要方法: width() height() innerWidth() innerHeight() outerWidth() outerHei ...

  8. 移除数组中指定键(Yii2)

    /** * 移除数组中指定key * @param $data * @param $key * @return array */ public static function removeKey($d ...

  9. js 学习四 对象应用 吃货游戏

    游戏来源于 Mdn学习网站: 该例子用于对象的理解非常有效(建议看完上面网站的内容在开始练习) 弹球 body { margin: 0; overflow: hidden; font-family: ...

  10. 日语能力考试N2级核心词汇必备—接续词

    日语能力考试N2级核心词汇必备—接续词 顺接 だから 因为......所以......(下文可用命令,意志劝诱等)その結果  其结果(口语,书面语都行,但是比较生硬)したがって  从而,因而(书面语, ...