drcarter의 DevLog


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