Android 图像处理(浮雕、复古、怀旧等)
来源:互联网 发布:制作搞笑视频的软件 编辑:程序博客网 时间:2024/04/28 12:38
import android.graphics.Bitmap;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.ColorMatrix;import android.graphics.ColorMatrixColorFilter;import android.graphics.Paint;public class ImageHelper { /** * 色调、色相、亮度 * @param bm * @param hue * @param saturation * @param lum * @return */ public static Bitmap handleImageEffect(Bitmap bm, float hue, float saturation, float lum) { Bitmap bmp = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmp); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); ColorMatrix hueMatrix = new ColorMatrix(); hueMatrix.setRotate(0, hue); hueMatrix.setRotate(1, hue); hueMatrix.setRotate(2, hue); ColorMatrix saturationMatrix = new ColorMatrix(); saturationMatrix.setSaturation(saturation); ColorMatrix lumMatrix = new ColorMatrix(); lumMatrix.setScale(lum, lum, lum, 1); ColorMatrix imageMatrix = new ColorMatrix(); imageMatrix.postConcat(hueMatrix); imageMatrix.postConcat(saturationMatrix); imageMatrix.postConcat(lumMatrix); paint.setColorFilter(new ColorMatrixColorFilter(imageMatrix)); canvas.drawBitmap(bm, 0, 0, paint); return bmp; } /** * 底片 * @param bm * @return */ public static Bitmap handleImageNegative(Bitmap bm) { int width = bm.getWidth(); int height = bm.getHeight(); int color; int r, g, b, a; Bitmap bmp = Bitmap.createBitmap(width, height , Bitmap.Config.ARGB_8888); int[] oldPx = new int[width * height]; int[] newPx = new int[width * height]; bm.getPixels(oldPx, 0, width, 0, 0, width, height); for (int i = 0; i < width * height; i++) { color = oldPx[i]; r = Color.red(color); g = Color.green(color); b = Color.blue(color); a = Color.alpha(color); r = 255 - r; g = 255 - g; b = 255 - b; if (r > 255) { r = 255; } else if (r < 0) { r = 0; } if (g > 255) { g = 255; } else if (g < 0) { g = 0; } if (b > 255) { b = 255; } else if (b < 0) { b = 0; } newPx[i] = Color.argb(a, r, g, b); } bmp.setPixels(newPx, 0, width, 0, 0, width, height); return bmp; } /** * 怀旧 * @param bm * @return */ public static Bitmap handleImagePixelsOldPhoto(Bitmap bm) { Bitmap bmp = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), Bitmap.Config.ARGB_8888); int width = bm.getWidth(); int height = bm.getHeight(); int color = 0; int r, g, b, a, r1, g1, b1; int[] oldPx = new int[width * height]; int[] newPx = new int[width * height]; bm.getPixels(oldPx, 0, bm.getWidth(), 0, 0, width, height); for (int i = 0; i < width * height; i++) { color = oldPx[i]; a = Color.alpha(color); r = Color.red(color); g = Color.green(color); b = Color.blue(color); r1 = (int) (0.393 * r + 0.769 * g + 0.189 * b); g1 = (int) (0.349 * r + 0.686 * g + 0.168 * b); b1 = (int) (0.272 * r + 0.534 * g + 0.131 * b); if (r1 > 255) { r1 = 255; } if (g1 > 255) { g1 = 255; } if (b1 > 255) { b1 = 255; } newPx[i] = Color.argb(a, r1, g1, b1); } bmp.setPixels(newPx, 0, width, 0, 0, width, height); return bmp; } /** * 浮雕 * @param bm * @return */ public static Bitmap handleImagePixelsRelief(Bitmap bm) { Bitmap bmp = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), Bitmap.Config.ARGB_8888); int width = bm.getWidth(); int height = bm.getHeight(); int color = 0, colorBefore = 0; int a, r, g, b; int r1, g1, b1; int[] oldPx = new int[width * height]; int[] newPx = new int[width * height]; bm.getPixels(oldPx, 0, bm.getWidth(), 0, 0, width, height); for (int i = 1; i < width * height; i++) { colorBefore = oldPx[i - 1]; a = Color.alpha(colorBefore); r = Color.red(colorBefore); g = Color.green(colorBefore); b = Color.blue(colorBefore); color = oldPx[i]; r1 = Color.red(color); g1 = Color.green(color); b1 = Color.blue(color); r = (r - r1 + 127); g = (g - g1 + 127); b = (b - b1 + 127); if (r > 255) { r = 255; } if (g > 255) { g = 255; } if (b > 255) { b = 255; } newPx[i] = Color.argb(a, r, g, b); } bmp.setPixels(newPx, 0, width, 0, 0, width, height); return bmp; }}
0 0
- Android 图像处理(浮雕、复古、怀旧等)
- Android图像处理(三)负片,怀旧,浮雕,灰度,圆角,油画和左右对称
- Android图像处理(二)底片效果、怀旧效果、浮雕效果
- android图像处理(3)浮雕效果
- android图像处理(3)浮雕效果
- android图像处理(3)浮雕效果
- android图像处理(3)浮雕效果
- 【Android图像处理】浮雕滤镜(效果)
- 图像处理软件开发记录(六) 图像特效(浮雕、怀旧)
- Android图像处理(2):怀旧效果
- Android图像处理(2):怀旧效果
- Android图像处理(2):怀旧效果
- Android图像处理_浮雕效果
- 图像滤镜特效(反色、浮雕、雕刻、怀旧、冰冻、暗调)(一)
- 图像处理 浮雕效果
- Delphi图像处理 -- 灰色浮雕
- Delphi图像处理 -- 彩色浮雕
- Delphi图像处理 -- 填充浮雕
- nyoj 完全背包 311 (完全背包) 好题
- ubuntu不能设置高分辨率问题的解决方法
- <input type="file">定义样式并获取上传文件路径及指定文件类型
- 基于冒泡排序算法的中值滤波器
- c++学习笔记十三
- Android 图像处理(浮雕、复古、怀旧等)
- 敌兵布阵
- c++学习笔记十四
- 【ES6系列】模块Module
- 黑马程序员——Java基础---正则表达式
- android:使用webview加载网页
- Windows下PCI9054驱动程序开发环境搭建及常见问题解决
- c++学习笔记十五
- Unity Profiler工具的使用