首页 技术 正文
技术 2022年11月14日
0 收藏 715 点赞 4,168 浏览 1623 个字
//使用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);      }

?

1234567891011121314151617181920212223 //使用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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,000
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,512
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,358
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,141
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,771
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,849