method to build a Bitmap to be previewed/Fx'd after capture - Android Graphics

Android examples for Graphics:Bitmap Read

Description

method to build a Bitmap to be previewed/Fx'd after capture

Demo Code


//package com.java2s;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;

import android.view.Surface;

public class Main {
    /**/*from   w  w  w .j ava 2  s.c o m*/
     * method to build a Bitmap to be previewed/Fx'd after capture
     * 
     * @param imageData
     * @param orientation
     * @param width
     * @param height
     * @param imageQuality
     * @return
     */
    public static Bitmap previewImage(byte[] imageData, int orientation,
            int width, int height, int imageQuality) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = imageQuality;
        Bitmap pic = BitmapFactory.decodeByteArray(imageData, 0,
                imageData.length, options);

        int rotate = 0;
        if (orientation == Surface.ROTATION_0) {
            rotate = 90;
        } else if (orientation == Surface.ROTATION_270) {
            rotate = 180;
        }

        if (rotate != 0) {
            int w = pic.getWidth();
            int h = pic.getHeight();
            Matrix mtx = new Matrix();
            mtx.postRotate(rotate);
            pic = Bitmap.createBitmap(pic, 0, 0, w, h, mtx, true);
        }

        pic = pic.copy(Bitmap.Config.ARGB_8888, true);
        return pic;
    }
}

Related Tutorials