Android图像处理之冰冻效果
2024-09-23 19:44:32
原图 效果图
代码:
- package com.color;
- import android.content.Context;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.graphics.Canvas;
- import android.graphics.Color;
- import android.graphics.Paint;
- import android.util.AttributeSet;
- import android.widget.ImageView;
- public class ColorView extends ImageView {
- private Paint myPaint = null;
- private Bitmap bitmap = null;
- private int width, height;
- private int[] oldPixels;
- private int[] newPixels;
- private int color, color2;
- private int pixelsR, pixelsG, pixelsB, pixelsA, pixelsR2, pixelsG2,
- pixelsB2;
- public ColorView(Context context, AttributeSet attrs) {
- super(context, attrs);
- bitmap = BitmapFactory.decodeResource(context.getResources(),
- R.drawable.ww);
- width = bitmap.getWidth();
- height = bitmap.getHeight();
- oldPixels = new int[width * height];
- newPixels = new int[width * height];
- invalidate();
- }
- @Override
- protected void onDraw(Canvas canvas) {
- super.onDraw(canvas);
- // 获取像素
- bitmap.getPixels(oldPixels, 0, width, 0, 0, width, height);
- for (int i = 1; i < height * width; i++) {
- color = oldPixels[i];
- // 获取RGB分量
- pixelsA = Color.alpha(color);
- pixelsR = Color.red(color);
- pixelsG = Color.green(color);
- pixelsB = Color.blue(color);
- //R
- int pixel = pixelsR - pixelsG - pixelsB;
- pixel = pixel * 3 / 2;
- if (pixel < 0) {
- pixel = -pixel;
- }
- if (pixel > 255){
- pixel = 255;
- }
- pixelsR = pixel; // 计算后重置R值,以下类同
- //G
- pixel = pixelsG - pixelsR - pixelsB;
- pixel = pixel * 3 / 2;
- if (pixel < 0) {
- pixel = -pixel;
- }
- if (pixel > 255){
- pixel = 255;
- }
- pixelsG = pixel;
- //B
- pixel = pixelsB - pixelsR - pixelsG;
- pixel = pixel * 3 / 2;
- if (pixel < 0) {
- pixel = -pixel;
- }
- if (pixel > 255){
- pixel = 255;
- }
- pixelsB = pixel;
- // 根据新的RGB生成新像素
- newPixels[i] = Color.argb(pixelsA, pixelsR, pixelsG, pixelsB);
- }
- // 根据新像素生成新图片
- bitmap.setPixels(newPixels, 0, width, 0, 0, width, height);
- canvas.drawBitmap(bitmap, 0, 0, myPaint);
- }
- }
参考博文:点击打开链接
最新文章
- linux -小记(2)问题:yum 安装报错";Another app is currently holding the yum lock; waiting for it to exit... ...: yum Memory : 26 M RSS (868 MB VSZ) Started: Wed Oct 26 22:48:24 2016 - 0";
- MyBatis知多少(17)MyBatis和JDBC
- android 学习随笔十五(Activity的生命周期与摧毁时返回数据 )
- APK反编译之一
- php生成缩略图
- PHP不显示报错了怎么办~
- 全球最快的JS模板引擎
- paip.tree 生成目录树到txt后的折叠查看
- Software development process
- linkin大话数据结构--Queue
- jQuery学习之旅 Item4 细说DOM操作
- nodejs搭建web服务器
- python 获取mac地址zz
- .net开发COM组件之组件签名&;注册
- C# 无法将类型为“__DynamicallyInvokableAttribute”的对象强制转换为类型...
- Git Learning3 Eclipse Tools(未完成)
- 有哪些api接口可以实现微信自动唤醒浏览器,下载app,打开网页
- javascript的hashCode实现
- kali蓝牙连接
- inline-block元素间隙问题原因及解决方法
热门文章
- numa 和 mysql
- Goldengate进程的合并与拆分规范
- iOS——扬声器与听筒的切换
- Centos7(阿里云服务器)安装Anaconda的详细步骤与心得
- 在ubuntu上使用华为的3G无线上网卡 - usb_modeswitch
- CSS动画框架Loaders.css +animate.css
- RC Immix
- python note #1
- 洛谷 P1952 火星上的加法运算_NOI导刊2009提高(3)
- [Poi] Use Poi to Build an Index.js with Modern JavaScript Features