Android Bitmap图片缩放优化,用canvas替代Matrix进行缩放,解决一些错我
来源:互联网 发布:中国网络暴力现状 编辑:程序博客网 时间:2024/06/05 06:12
前面用Matrix来缩放Bitmap,发现有些情况下会抛出错误,导致图片空白。
/** * 缩放 * * @param bm * @param newWidth * @param newHeight * @return */// public synchronized static Bitmap scaleImage(boolean isApplyRadio,Bitmap bm, int newWidth, int newHeight) {//// //应用图标缩放// if(isApplyRadio&&iconScaleRadio!=1f){// newWidth= (int) (newWidth*iconScaleRadio);// newHeight= (int) (newHeight*iconScaleRadio);// }//// if (bm == null) {// return null;// }// int width = bm.getWidth();// int height = bm.getHeight();// float scaleWidth = ((float) newWidth) / width;// float scaleHeight = ((float) newHeight) / height;// Matrix matrix = new Matrix();// matrix.postScale(scaleWidth, scaleHeight);// Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);// if (bm != null & !bm.isRecycled()) {// bm.recycle();// bm = null;// }// return newbm;// }
private static PaintFlagsDrawFilter pfd = new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG); public synchronized static Bitmap scaleImageCavans(boolean isApplyRadio,Bitmap bm, int newWidth, int newHeight) { //应用图标缩放 if(isApplyRadio&&iconScaleRadio!=1f){ newWidth= (int) (newWidth*iconScaleRadio); newHeight= (int) (newHeight*iconScaleRadio); } if (bm == null) { return null; } int width = bm.getWidth(); int height = bm.getHeight(); float scaleWidth = ((float) newWidth) / width; float scaleHeight = ((float) newHeight) / height; Bitmap newbm = Bitmap.createBitmap(newWidth, newWidth, Bitmap.Config.ARGB_8888); mCanvas.setBitmap(newbm); mPaint.setXfermode(null); mPaint.setAntiAlias(true); mCanvas.save(); mCanvas.scale(scaleWidth, scaleHeight); //保证图标不失真 mCanvas.setDrawFilter(pfd); mCanvas.drawBitmap(bm,0,0,null); mCanvas.restore(); if (bm != null & !bm.isRecycled()) { bm.recycle(); bm = null; } return newbm; }
0 0
- Android Bitmap图片缩放优化,用canvas替代Matrix进行缩放,解决一些错我
- Android 图片缩放-Matrix
- Android 图片缩放-Matrix
- 缩放图片:Matrix与Bitmap的使用
- android Bitmap 读取缩放图片
- Android Matrix对图片进行倾斜、缩放变换
- Gesture控制图片缩放&Canvas: trying to use a recycled bitmap android.graphics.Bitmap异常
- android对图片进行缩放
- Android图片旋转,缩放,位移,倾斜,对称完整示例(二)——Bitmap.createBitmap()和Matrix
- Bitmap图片缩放处理
- Bitmap 图片缩放
- Android Bitmap转换以及图片的缩放
- Android中图片Bitmap的缩放
- Android bitmap 图片缩放,压缩处理
- Android中图片Bitmap的缩放
- Android中图片Bitmap的缩放
- Android中图片Bitmap的缩放
- 图片处理(旋转,平移,缩放)View---Canvas;Paint;Bitmap
- A New Change Problem
- ANSIC 类型限定词
- 【数据结构 笔记02】栈的应用
- dom4j 快速入门文档
- mysql登陆密码过期 mac环境
- Android Bitmap图片缩放优化,用canvas替代Matrix进行缩放,解决一些错我
- java优化导致引用的常量不是正确的值
- 关于Cocos2d-x中触摸事件的setSwallowTouches 方法的解析
- node.js fs,http 模块用法
- 排序算法(2)冒泡排序,快速排序,归并排序和基数排序MSD,LSD
- 清除iOS工程里未使用的图片
- 我的保存的一些Android大神的連接
- RTC驱动修改
- 360追日团队APT报告:摩诃草组织(APT-C-09) 20160810