安卓SDK之YUV-Image

来源:互联网 发布:mac地址 冲突 编辑:程序博客网 时间:2024/06/06 03:06


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

1. 引入包:   

import java.io.ByteArrayOutputStream;import android.hardware.Camera;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.YuvImage;import android.graphics.ImageFormat;import android.graphics.Rect;import android.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(Rect rectangle, int quality, OutputStream stream)
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 in PixelFormat.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/

//@Overridepublic void changeYUV(byte[] data, Bitmap bmp){final int Width  = myCamera.getParameters().getPreviewSize().width;final int Height = myCamera.getParameters().getPreviewSize().height; YuvImage image = new YuvImage(data, ImageFormat.NV21,Width, Height, null); if(image!=null){             ByteArrayOutputStream stream = new ByteArrayOutputStream();             image.compressToJpeg(new Rect(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();                      }}

0 0
原创粉丝点击