fill Grayscale Bitmap From Data - Android android.graphics

Android examples for android.graphics:Bitmap Operation

Description

fill Grayscale Bitmap From Data

Demo Code

import android.graphics.Bitmap;
import android.hardware.Camera;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.List;

public class Main{


    public static Bitmap fillGrayscaleBitmapFromData(Bitmap bitmap,
            byte[] cdata, int width, int height, int[] pixelBuffer) {
        int npixels = width * height;
        for (int i = 0; i < npixels; i++) {
            int g = 0xff & cdata[i];
            pixelBuffer[i] = (255 << 24) + (g << 16) + (g << 8) + g;
        }//from ww w.  j av a  2s  .  co  m
        bitmap.setPixels(pixelBuffer, 0, width, 0, 0, width, height);
        return bitmap;
    }

}

Related Tutorials