반응형
public static Bitmap doGreyscale(Bitmap src)
{
final double GS_RED = 0.299;
final double GS_GREEN = 0.587;
final double GS_BLUE = 0.114;
int width = src.getWidth();
int height = src.getHeight();
Bitmap resultBitmap = Bitmap.createBitmap(width, height, src.getConfig());
int A, R, G, B;
int pixel;
for (int x = 0; x < width; ++x)
{
for (int y = 0; y < height; ++y)
{
pixel = src.getPixel(x, y);
A = Color.alpha(pixel);
R = Color.red(pixel);
G = Color.green(pixel);
B = Color.blue(pixel);
R = G = B = (int) (GS_RED * R + GS_GREEN * G + GS_BLUE * B);
resultBitmap.setPixel(x, y, Color.argb(A, R, G, B));
}
}
return resultBitmap;
}
반응형
'Android' 카테고리의 다른 글
| [Android] MediaCodec 을 이용한 player 만들기. (6) | 2014.08.19 |
|---|---|
| [Android] Android Library project를 ant로 build 시 renderscript.opt.level Troubleshooting (0) | 2014.07.21 |
| [Android] Image Processing – Invert Image (1) | 2014.06.18 |
| OutOfMemoryError: bitmap size exceeds VM budget (1) | 2014.06.16 |
| [Android]AlarmManager를 이용하여 특정 요일, 시간 마다 알람 울리기. (9) | 2014.06.02 |