android图像处理方式有哪些内容,Android图像处理总结。

本文介绍了在安卓平台中进行图像处理的两种主要方法:一是使用颜色矩阵来改变图像的颜色效果,包括调整色调、饱和度和亮度;二是直接操作像素点实现图片的怀旧效果,通过特定的色彩转换公式对每个像素进行处理。这两种技术可以用于创建各种视觉效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安卓中图像处理主要通过两种方式:改变颜色矩阵,改变像素点

改变颜色矩阵

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 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;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值