package com.asiainfo.imageprocess.utils;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
/**
* 作者:小木箱 邮箱:yangzy3@asiainfo.com 创建时间:2017年02月14日19点33分 描述: 图像处理工具类
*/
public class ImageHelper {
/***
* @param hue 色调
* @param saturation 饱和度
* @param lum 透明度
* @return bmp
*/
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;
}
/***
* 底片效果
*/
public static Bitmap handlerImageNegative(Bitmap bm) {
int width = bm.getWidth();
int height = bm.getHeight();
int arraySize = width * height;
int color;
int r, g, b, a;
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
int[] oldPX = new int[arraySize];
int[] newPX = new int[arraySize];
bm.getPixels(oldPX, 0, width, 0, 0, width, height);
for (int i = 0; i < arraySize; 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);
}
bitmap.setPixels(newPX, 0, width, 0, 0, width, height);
return bitmap;
}
/***
* 怀旧效果
*/
public static Bitmap handlerImagePixelsOldPhoto(Bitmap bm) {
int width = bm.getWidth();
int height = bm.getHeight();
int arraySize = width * height;
int color = 0;
int r, g, b, a, r1, g1, b1;
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
int[] oldPX = new int[arraySize];
int[] newPX = new int[arraySize];
bm.getPixels(oldPX, 0, width, 0, 0, width, height);
for (int i = 0; i < arraySize; i++) {
color = oldPX[i];
r = Color.red(color);
g = Color.green(color);
b = Color.blue(color);
a = Color.alpha(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);
}
bitmap.setPixels(newPX, 0, width, 0, 0, width, height);
return bitmap;
}
/***
* 浮雕效果
*/
public static Bitmap handlerImagePixelsRelief(Bitmap bm) {
int width = bm.getWidth();
int height = bm.getHeight();
int arraySize = width * height;
int color = 0, colorBefore = 0;
int r, g, b, a, r1, g1, b1;
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
int[] oldPX = new int[arraySize];
int[] newPX = new int[arraySize];
bm.getPixels(oldPX, 0, width, 0, 0, width, height);
for (int i = 1; i < arraySize; i++) {
colorBefore = oldPX[i - 1];
r = Color.red(colorBefore);
g = Color.green(colorBefore);
b = Color.blue(colorBefore);
a = Color.alpha(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);
}
bitmap.setPixels(newPX, 0, width, 0, 0, width, height);
return bitmap;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Android图像处理.zip
共60个文件
xml:23个
java:17个
png:5个
需积分: 5 0 下载量 121 浏览量
2024-04-15
00:15:27
上传
评论
收藏 292KB ZIP 举报
温馨提示
【项目资源】:包含前端、后端、移动开发、人工智能、物联网、信息化管理、数据库、硬件开发、大数据、课程资源等各种技术项目的源码。包括C++、Java、python、web、C#、EDA等项目的源码。 【适用人群】:适用于希望学习不同技术领域的小白或进阶学习者。可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。 【附加价值】:项目具有较高的学习借鉴价值,也可直接拿来修改复刻。对于有一定基础或热衷于研究的人来说,可以在这些基础代码上进行修改和扩展,实现其他功能。 【沟通交流】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。鼓励下载和使用,并欢迎大家互相学习,共同进步。
资源推荐
资源详情
资源评论
收起资源包目录
Android图像处理.zip (60个子文件)
newPic
gradle.properties 730B
gradle
wrapper
gradle-wrapper.jar 52KB
gradle-wrapper.properties 233B
gradlew.bat 2KB
build.gradle 498B
.idea
runConfigurations.xml 564B
vcs.xml 180B
misc.xml 4KB
compiler.xml 686B
modules.xml 411B
gradle.xml 714B
encodings.xml 159B
copyright
profiles_settings.xml 74B
settings.gradle 24B
gradlew 5KB
.gitignore 118B
ImageProcess
src
androidTest
java
com
asiainfo
imageprocess
ExampleInstrumentedTest.java 765B
test
java
com
asiainfo
imageprocess
ExampleUnitTest.java 414B
main
java
com
asiainfo
imageprocess
utils
ImageHelper.java 5KB
activity
ColorMatrixActivity.java 4KB
BitmapShaderActivity.java 372B
ReflectActivity.java 361B
ImageProcessActivity.java 3KB
MeshActivity.java 355B
RoundRectXfermodeActivity.java 484B
PrimaryColorActivity.java 3KB
PixelsActivity.java 1KB
MatrixActivity.java 3KB
view
BitmapShaderView.java 1KB
MeshView.java 2KB
ImageMatrixView.java 1KB
RoundRectXfermodeView.java 2KB
ReflectView.java 2KB
res
mipmap-xxhdpi
ic_launcher.png 8KB
mipmap-hdpi
ic_launcher.png 3KB
drawable-xhdpi
test1.jpg 41KB
test3.jpg 40KB
test4.jpg 61KB
test2.jpg 44KB
mipmap-mdpi
ic_launcher.png 2KB
mipmap-xxxhdpi
ic_launcher.png 10KB
mipmap-xhdpi
ic_launcher.png 5KB
values-w820dp
dimens.xml 358B
values
dimens.xml 211B
colors.xml 208B
strings.xml 75B
styles.xml 383B
layout
activity_reflect.xml 522B
activity_image_process.xml 2KB
activity_mesh.xml 498B
activity_matrix.xml 1KB
round_rect_xfermode_view.xml 459B
activity_bitmap_shader.xml 558B
activity_pixels.xml 1KB
activity_color_matrix.xml 1KB
activity_primary_color.xml 1KB
AndroidManifest.xml 1KB
proguard-rules.pro 669B
build.gradle 873B
.gitignore 7B
共 60 条
- 1
资源评论
白话Learning
- 粉丝: 3108
- 资源: 2465
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- HM2305B-VB一款P-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- 基于52单片机、ADC0832、LCD1602、两个74HC393和一个74HC08的频率测量计 不能用,请私我
- HM2302-VB一款N-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- python实战项目-学生成绩管理系统(基础版)
- 微信小程序源码 实现查公交 滴滴公交 app 源码下载
- HM2302E-VB一款N-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- 基于C#图片相似度比较,感知哈希算法
- VR开发的概要介绍与分析
- 自动驾驶定位系列教程七:点云畸变补偿.pdf
- HM2302D-VB一款N-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功