decode YUV420SP Color - Android Graphics

Android examples for Graphics:Color

Description

decode YUV420SP Color

Demo Code


//package com.java2s;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

import android.graphics.Rect;

import android.graphics.YuvImage;

public class Main {
    public static Bitmap decodeYUV420SP_newApi(byte[] yuv420sp, int width,
            int height, int format, int quality) {
        YuvImage image = new YuvImage(yuv420sp, format, width, height, null);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        image.compressToJpeg(/*  w w  w  . ja  v a2  s  . c om*/
                new Rect(0, 0, image.getWidth(), image.getHeight()),
                quality, bos);
        ByteArrayInputStream bis = new ByteArrayInputStream(
                bos.toByteArray());
        return BitmapFactory.decodeStream(bis);
    }
}

Related Tutorials