Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android圖像處理

android圖像處理

編輯:關於Android編程

圖像分析之RGBA模型


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;

}
}


}
  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved