图片处理常用方法总结
来源:互联网 发布:flotherm软件英文翻译 编辑:程序博客网 时间:2024/05/21 11:17
1. 高斯模式处理
查考笔记"高斯模式"部分,有专门总结
2.裁剪图片(按屏幕比例)
下面这个方法是将传入的bitmap(当初写这个方法的时候是取得系统壁纸)根据屏幕尺寸来裁剪
public Bitmap setAndcropWallpaper(Context context,Bitmap wallpaper) {
Bitmap targetBitmap = null;
if (wallpaper != null) {
try {
int wallpaperWidth = wallpaper.getWidth();
int wallpaperHeight = wallpaper.getHeight();
DisplayMetrics dm = new DisplayMetrics();
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
wm.getDefaultDisplay().getMetrics(dm);
int screenWidth = dm.widthPixels;// 1080
int screenHeight = dm.heightPixels;// 1920
float defaultScreen = (float)screenHeight / (float)screenWidth;
Log.d(TAG, "defaultScreen=" + defaultScreen);
if (defaultScreen < 1) {
defaultScreen = (float)screenWidth / (float)screenHeight;
}
float bitmapSize = (float)wallpaperHeight /(float)wallpaperWidth;
int disWidth = 0;
int disHeight = 0;
int captureBitmapWidth = wallpaperWidth;
int captureBitmapHeight = wallpaperHeight;
Log.d(TAG, "defaultScreen=" + defaultScreen + " bitmapSize="
+ bitmapSize);
if (defaultScreen > bitmapSize) { // bitmapHeight is min , capture bitmapWidth
captureBitmapWidth = (int) ((screenWidth * wallpaperHeight) / screenHeight);
disWidth = wallpaperWidth - captureBitmapWidth;
} else if (defaultScreen < bitmapSize) {
captureBitmapHeight = (int) ((wallpaperWidth * screenHeight) / screenWidth);
disHeight = wallpaperHeight - captureBitmapHeight;
}
if (DEBUG) {
Log.d(TAG, "setAndcropWallpaper ----- disWidth="
+ disWidth + ",disHeight=" + disHeight
+ ",captureBitmapWidth=" + captureBitmapWidth
+ ",captureBitmapHeight=" + captureBitmapHeight
+ " screenWidth=" + screenWidth + " screenHeight="
+ screenHeight);
}
if (disWidth < 0 || disHeight < 0) {
return null;
}
targetBitmap = Bitmap.createBitmap(wallpaper, disWidth / 2,
disHeight / 2, captureBitmapWidth, captureBitmapHeight);
float scaleWidth = (float) ((float) captureBitmapWidth / screenWidth);
float scaleHeight = (float) ((float) captureBitmapHeight / screenHeight);
Log.d(TAG, "scaleWidth=" + scaleWidth + " scaleHeight="
+ scaleHeight);
if ((targetBitmap != null)
&& (scaleWidth != 1 || scaleHeight != 1)) {
Matrix matrix = new Matrix();
/**
* 处理之后的图片小于屏幕尺寸 处理原始的图片比例和屏幕比例是一致,但尺寸比屏幕大
*/
if (scaleWidth != 0.0f && scaleHeight != 0.0f
&& (scaleWidth != 1.0f || scaleHeight != 1.0f)) {//
scaleWidth = 1.0f / scaleWidth;
scaleHeight = 1.0f / scaleHeight;
Log.d(TAG, "---scaleWidth=" + scaleWidth + " scaleHeight=" + scaleHeight);
}
matrix.postScale(scaleWidth, scaleHeight);
int width = targetBitmap.getWidth();
int height = targetBitmap.getHeight();
Log.d(TAG, "---width=" + width + " height=" + height);
targetBitmap = Bitmap.createBitmap(targetBitmap, 0, 0,
screenWidth > width ? width : screenWidth,
screenHeight > height ? height : screenHeight,
matrix, true);
}
} catch (OutOfMemoryError e) {
e.printStackTrace();
}
}
return targetBitmap;
}
0 0
- 图片处理常用方法总结
- 图片处理方法总结
- 图片处理的常用方法
- android 图片处理常用方法
- android 常用图片处理效果总结
- Android提高 - 图片一些常用处理方法
- 总结-处理字符串常用方法类
- 图像处理常用插值方法总结
- 图像处理常用插值方法总结
- 图像处理常用插值方法总结
- JS常用字符串处理方法总结
- 图像处理常用插值方法总结
- 图像处理常用插值方法总结
- 图像处理常用插值方法总结
- Android图片处理总结五:Bitmap方法总结
- PS常用快捷键及快捷的处理图片方法
- 常用图片处理技巧
- 常用的图片处理
- 新浪微博粉丝爬虫-wap站只能爬取20页-
- vi/vim使用进阶: 自动补全
- 32位寄存器
- response.encodeURL的用法
- 如何对图片进行SEO优化?只需三步
- 图片处理常用方法总结
- java线程之并发访问
- 定时任务Alarm的深入理解
- 仿**宝钱额添加动画 animator
- 寒假作业
- 使用git上传代码到github
- h5 新标签 ——LBS 属性
- 最大似然分类法MLC
- iOS CoreData介绍和使用(以及一些注意事项)