- 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;
- }
- }
转载于:https://blog.51cto.com/3387980/838370