Java tutorial
//package com.java2s; //License from project: Open Source License import android.graphics.Bitmap; public class Main { /** Sets pixels in the given bitmap to a grayscale image from the byte array from a camera preview, * assumed to be in YUV (NV21) format with brightness pixels first. */ public static Bitmap fillGrayscaleBitmapFromCameraData(Bitmap bitmap, byte[] cdata, int width, int height) { int[] pixels = new int[cdata.length]; for (int i = 0; i < cdata.length; i++) { int g = 0xff & cdata[i]; pixels[i] = (255 << 24) + (g << 16) + (g << 8) + g; } bitmap.setPixels(pixels, 0, width, 0, 0, width, height); return bitmap; } }