Android Bitmap颜色、亮度、饱和度等变化
来源:互联网 发布:js修改css样式 生效 编辑:程序博客网 时间:2024/06/13 02:11
颜色矩阵 ColorMatrix cm = new ColorMatrix();
paint.setColorFilter(new ColorMatrixColorFilter(cm));
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
New Red Value = 1*128 + 0*128 + 0*128 + 0*0 + 0
New Blue Value = 0*128 + 1*128 + 0*128 + 0*0 + 0
New Green Value = 0*128 + 0*128 + 1*128 + 0*0 + 0
New Alpha Value = 0*128 + 0*128 + 0*128 + 1*0 + 0
ColorMatrix cm = new ColorMatrix();
cm.set(new float[] {
2, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0
});
paint.setColorFilter(new ColorMatrixColorFilter(cm));
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity" > <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:onClick="click" android:text="拷贝一个位图" /> <ImageView android:id="@+id/iv1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ImageView android:id="@+id/iv2" android:layout_width="wrap_content" android:layout_height="wrap_content" /></LinearLayout>
public class MainActivity extends Activity { private ImageView iv1,iv2; private Bitmap alterBitmap; private Bitmap srcBmp; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); iv1 = (ImageView) findViewById(R.id.iv1); iv2 = (ImageView) findViewById(R.id.iv2); //给第一个imageview默认设置一个位图 srcBmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); iv1.setImageBitmap(srcBmp); //创建原图的一个副本。 可修改 创建的是一个空白的图形。 alterBitmap = Bitmap.createBitmap(srcBmp.getWidth()*2, srcBmp.getHeight()*2,srcBmp.getConfig()); } /** * 创建原图 bm的一个拷贝。副本 * @param view */ public void click(View view){ //1.准备一个画板 在上面放上准备好的 空白的位图 Canvas canvas = new Canvas(alterBitmap); //2.准备一个画笔 Paint paint = new Paint(); paint.setColor(Color.BLACK); //3.画画 Matrix m = new Matrix(); ColorMatrix cm = new ColorMatrix(); cm.set(new float[] { 0.5f, 0, 0, 0, 0, 0, 0.8f, 0, 0, 0, 0, 0, 0.6f, 0, 0, 0, 0, 0, 1, 0 }); paint.setColorFilter(new ColorMatrixColorFilter(cm)); canvas.drawBitmap(srcBmp, m, paint); iv2.setImageBitmap(alterBitmap);//把原图的副本设置到界面上。 }}
获取Exif图片信息
//从文件获取exif信息ExifInterface ei = new ExifInterface(imageFilePath);String imageDescription = ei.getAttribute("ImageDescription");if (imageDescription != null){Log.v("EXIF", imageDescription);}//把exif信息写到文件:ExifInterface ei = new ExifInterface(imageFilePath);ei.setAttribute("ImageDescription","Something New");
从gallery获取一个图片
Intent intent = new Intent(Intent.ACTION_PICK);intent.setType(“image/*”);intent.getData() 获取image的uriBitmap bmp = BitmapFactory.decodeStream(getContentResolver().��openInputStream(imageFileUri), null, bmpFactoryOptions);
变换图像的亮度
ColorMatrix cm = new ColorMatrix();float contrast = 2;cm.set(new float[] {contrast, 0, 0, 0, 0,0, contrast, 0, 0, 0,0, 0, contrast, 0, 0,0, 0, 0, 1, 0 });paint.setColorFilter(new ColorMatrixColorFilter(cm));
更改图片饱和度
ColorMatrix cm = new ColorMatrix();cm.setSaturation(.5f);paint.setColorFilter(new ColorMatrixColorFilter(cm));
图片合成
Bitmap drawingBitmap = Bitmap.createBitmap(bmp1.getWidth(),��bmp1.getHeight(), bmp1.getConfig());canvas = new Canvas(drawingBitmap);paint = new Paint();canvas.drawBitmap(bmp1, 0, 0, paint);paint.setXfermode(new PorterDuffXfermode(android.graphics.��PorterDuff.Mode.MULTIPLY));canvas.drawBitmap(bmp2, 0, 0, paint);
按指定path上绘制文字
Paint paint = new Paint();paint.setColor(Color.GREEN);paint.setTextSize(20);paint.setTypeface(Typeface.DEFAULT);Path p = new Path();p.moveTo(20, 20);p.lineTo(100, 150);p.lineTo(200, 220);canvas.drawTextOnPath("Hello this is text on a path", p, 0, 0, paint);
参考:
Android图片处理
0 0
- Android Bitmap颜色、亮度、饱和度等变化
- 颜色HSL(色调,饱和度,亮度)
- 关于颜色HSL(色度、饱和度、亮度)
- 颜色的三要素:色调,饱和度,和亮度。
- 颜色HSL(色调,饱和度,亮度)
- 关于颜色HSL(色度、饱和度、亮度)
- 关于颜色HSL(色度、饱和度、亮度)
- 修改图片颜色 色相 饱和度 亮度 ColorMatrix
- android 图像颜色处理 图像的亮度变换 更改图片饱和度
- 初学颜色矩阵(修改图像的色调,饱和度,亮度)
- 颜色的三要素:色调,饱和度,和亮度 HSI/HSV
- 【其它】颜色的知识--亮度、色相、饱和度、对比度
- android ImageView亮度变化
- cocos2d中更改CCSprite的饱和度、色相、亮度等属性
- 161_界面颜色亮度属性变化
- 亮度 对比度 饱和度 灰度
- 色调、亮度和饱和度
- Android改变图像的饱和度、亮度和对比度
- 数据结构简单应用
- Java对MySQL中的数据实现增查删改
- Android6.0 最新简洁配置权限,APP专用
- Android studio 注解的配置
- 无线轮播从网络加载图片 拉取数据get解析
- Android Bitmap颜色、亮度、饱和度等变化
- 【JMeter 菜鸟实操之三】性能自动化集成方案实施(监控资源、分布式压测等)
- 进程的开始与终止(exit和_exit区别)
- 山东省第三届ACM省赛 Pick apples
- XAMPP安装常见问题以及解决?
- hdu1787——GCD Again(欧拉函数入门)
- Unity各类数据库的基本操作(五)-- PlayerPrefs
- 合并两个有序链表
- oracle 12C 创建用户失败 解决方案