Android关于图片处理,更改图片灰度
16lz
2022-05-24
- 1. 更改图片灰度
- package com.huyanrui.photomodify;
- import android.app.Activity;
- import android.graphics.ColorMatrix;
- import android.graphics.ColorMatrixColorFilter;
- import android.graphics.drawable.Drawable;
- import android.os.Bundle;
- import android.widget.ImageView;
- public class PhotoModifyActivity extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- ImageView p_w_picpathView = (ImageView)findViewById(R.id.p_w_picpathView);
- ImageView p_w_picpathView2 = (ImageView)findViewById(R.id.p_w_picpathView2);
- p_w_picpathView2.setImageDrawable(huidu(R.drawable.icon));
- }
- //@param id 图片的ID
- private Drawable huidu(int id){
- Drawable drawable = getResources().getDrawable(id);
- drawable.mutate();//更改图片灰度
- ColorMatrix cMatrix = new ColorMatrix();
- cMatrix.setSaturation(0);
- ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(cMatrix);
- drawable.setColorFilter(colorFilter);
- return drawable;
- }
- }
更多相关文章
- Android如何截取当前View 为图片
- Android:ImageView 设置图片
- 介绍两个Android开源项目:Android显示GIF动画
- Java乔晓松-android中上传图片到服务器Tomcat(Struts2)
- Android图片下载缓存库picasso解析
- Android(安卓)调用相册 拍照 实现系统控件缩放 切割图片
- 更改Android模拟器中的hosts文件
- Android之selector标签
- android自定义progressbar图片大小自适应