public void onDraw(Canvas canvas) 에서





Sepia



Paint paint = new Paint();

paint.setAntiAlias(true);


ColorMatrix cm = new ColorMatrix(

new float[] { 0.3930000066757202f, 0.7689999938011169f,

0.1889999955892563f, 0, 0, 0.3490000069141388f,

0.6859999895095825f, 0.1679999977350235f, 0, 0,

0.2720000147819519f, 0.5339999794960022f,

0.1309999972581863f, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 });



paint.setColorFilter(new ColorMatrixColorFilter(cm));

canvas.drawBitmap( ... );





Gray Scale



cm = new ColorMatrix(


new float[] { 0.299f, 0.587f, 0.114f, 0, 0, 0.299f, 0.587f, 0.114f,

0, 0, 0.299f, 0.587f, 0.114f, 0, 0, 0, 0, 0, 1, 0 });





Reverse



cm = new ColorMatrix(


new float[] { -1, 0, 0, 0, 255, 0, -1, 0, 0, 255, 0, 0, -1, 0, 255,

0, 0, 0, 1, 0 });




Adjust Contrast


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)); 




Adjust Brightness


ColorMatrix cm = new ColorMatrix(); float brightness = -25;
cm.set(new float[] {

1, 0, 0, 0, brightness, 0, 1, 0, 0, brightness, 0, 0, 1, 0, brightness, 0, 0, 0, 1, 0 });

paint.setColorFilter(new ColorMatrixColorFilter(cm)); 




Adjust saturation


ColorMatrix cm = new ColorMatrix(); cm.setSaturation(.5f);
paint.setColorFilter(new ColorMatrixColorFilter(cm));

1보다 큰 값을 넘겨주면 채도가 늘어난다. 영(0)1 사이의 값이라면 채도는 줄어든다.








Posted by tenn
,