android图像处理

<h4>图像分析之RGBA模型</h4>
1.色调/色相--物体传递的颜色
ColorMatrix hueMatrix=new ColorMtrix();
hueMatrix.setRotate(0,hue);
hueMatrix.setRotate(1,hue);
hueMatrix.setRotate(2.hue);
2.饱和度--颜色的纯度,从(0)到100%饱和来进行描述
ColorMatrix saturationMatrix=new ColorMatrix();
saturationMatrix.setSaturation(saturation);
3.亮度/明度--颜色相对的明暗程度
ColorMatrix lumMatrix=new ColorMatrix();
lumMatrix.setScale(lum,lum,lun,1);
下面看主要代码
public class MainActivity extends Activity implements SeekBar.OnSeekBarChangeListener{


private ImageView imageView;
private SeekBar seekBar1,seekBar2,seekBar3;
private static int MAX=255;
private static int IN=127;
private MediaPlayer player;
float a,b,c;
private Bitmap bitmap;
   
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.g);
        imageView=(ImageView)findViewById(R.id.imageView);
        seekBar1=(SeekBar)findViewById(R.id.seekBar1);
        seekBar2=(SeekBar)findViewById(R.id.seekBar2);
        seekBar3=(SeekBar)findViewById(R.id.seekBar3);
        seekBar1.setOnSeekBarChangeListener(this);
        seekBar2.setOnSeekBarChangeListener(this);
        seekBar3.setOnSeekBarChangeListener(this);
        seekBar1.setMax(MAX);
        seekBar2.setMax(MAX);
        seekBar3.setMax(MAX);
        seekBar1.setProgress(IN);
        seekBar2.setProgress(IN);
        seekBar3.setProgress(IN);
        imageView.setImageBitmap(bitmap);
        player=MediaPlayer.create(this, R.raw.);
        player.start();
        }


  @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }


@Override
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
// TODO Auto-generated method stub
switch(arg0.getId()){
case R.id.seekBar1:
a=(arg1-IN)*1.0F/IN*180;
break;
case R.id.seekBar2:
b=arg1*1.0F/IN;
break;
case R.id.seekBar3:
c=arg1*1.0F/IN;
break;
}
imageView.setImageBitmap(new ImageHelper().handleImageView(bitmap, a, b, c));
}




class ImageHelper {


public static Bitmap handleImageView(Bitmap bm,float bug,float b,float c){

Bitmap bm1=Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas=new Canvas(bm1);
Paint paint=new Paint(Paint.ANTI_ALIAS_FLAG);
ColorMatrix hm=new ColorMatrix();
hm.setRotate(0, bug);
hm.setRotate(1, bug);
hm.setRotate(2, bug);
ColorMatrix sm=new ColorMatrix();
sm.setSaturation(b);
ColorMatrix lm=new ColorMatrix();
lm.setScale(c, c, c, 1);
ColorMatrix Imagem=new ColorMatrix();
Imagem.postConcat(hm);
Imagem.postConcat(sm);
Imagem.postConcat(lm);
paint.setColorFilter(new ColorMatrixColorFilter(Imagem));
canvas.drawBitmap(bm, 0, 0, paint);

return bm1;

}
}


}

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。