安卓SDK之YUV-Image

类参考链接:http://api.apkbus.com/reference/android/graphics/YuvImage.html

1. 引入包:

importjava.io.ByteArrayOutputStream;

importandroid.hardware.Camera;

importandroid.graphics.Bitmap;

importandroid.graphics.BitmapFactory;

importandroid.graphics.YuvImage;

importandroid.graphics.ImageFormat;

importandroid.graphics.Rect;

importandroid.graphics.Region;

安卓YUV_IMage包含四元组的YUV数据,contains YUV data and provides a method that compresses a region of the YUV data to a Jpeg,提供了一个向jpeg格式压缩的方法。

公有构造函数

YuvImage(byte[] yuv, int format, int width, int height, int[] strides)

Construct an YuvImage.

公有方法

booleancompressToJpeg(Rectrectangle, int quality,OutputStreamstream)

Compress a rectangle region in the YuvImage to a jpeg.

intgetHeight()

int[]getStrides()

intgetWidth()

byte[]getYuvData()

intgetYuvFormat()

释义:

Construct an YuvImage.

参数

yuvThe YUV data. In the case of more than one image plane, all the planes must be concatenated into a single byte array.

formatThe YUV data format as defined inPixelFormat.

widthThe width of the YuvImage.

heightThe height of the YuvImage.

strides(Optional) Row bytes of each image plane. If yuv contains padding, the stride of each image must be provided. If strides is null, the method assumes no padding and derives the row bytes by format and width itself.

抛出

IllegalArgumentExceptionif format is not support; width or height <= 0; or yuv is null.

2.  使用到的缓存类

参考链接:http://www.apihome.cn/api/java/ByteArrayOutputStream.html

参考链接:http://blog.chinaunix.net/uid-9789791-id-1997411.html

3. 转换为矩阵数据使用的代码

参考链接:http://eyehere.net/2011/android-camera-2/

//@Override

publicvoidchangeYUV(byte[] data, Bitmap bmp)

{

finalintWidth  = myCamera.getParameters().getPreviewSize().width;

finalintHeight = myCamera.getParameters().getPreviewSize().height;

YuvImage image =newYuvImage(data, ImageFormat.NV21,Width, Height,null);

if(image!=null){

ByteArrayOutputStream stream =newByteArrayOutputStream();

image.compressToJpeg(newRect(0,0, Width, Height),80, stream);

//Bitmap bmp = BitmapFactory.decodeByteArray(stream.toByteArray(), 0, stream.size());

bmp = BitmapFactory.decodeByteArray(stream.toByteArray(),0, stream.size());

stream.close();

}

}

安卓SDK之YUV-Image_第1张图片

你可能感兴趣的:(安卓SDK之YUV-Image)