본문 바로가기
컴퓨터관련

안드로이드 흑백 사진 만드는 법

by 기록이답이다 2014. 1. 7.
반응형

안드로이드 작업을 하던 중 online 인 사용자와 offline인 사용자의 구분을 해야 할 필요가 생겼다.

그래서 online인 사용자는 profile image를 color로

offline인 사용자는 profile image를 gray(흑백)로 표시가 되도록 하였다.

아래는 소스이다.

 

public static Bitmap getGrayImage() {

int width, height;     

height = bmpOriginal.getHeight();     
width = bmpOriginal.getWidth();          

Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);     
Canvas c = new Canvas(bmpGrayscale);     
Paint paint = new Paint();     
ColorMatrix cm = new ColorMatrix();     

cm.setSaturation(0);     
ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);   

  
paint.setColorFilter(f);     
c.drawBitmap(bmpOriginal, 0, 0, paint);     

return bmpGrayscale;

}

결과는 아래와 같다.  

 

 

반응형

'컴퓨터관련' 카테고리의 다른 글

안드로이드 마커 그리기  (0) 2014.01.07
안드로이드 overlay event  (0) 2014.01.07
안드로이드 삼각함수 이용하여 원 그리기  (0) 2014.01.07
android 좌표 계산  (2) 2014.01.07
Putty window title 고정시키기  (0) 2014.01.07