安卓SDK之YUV-Image


       类参考链接: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.
公有方法
boolean compressToJpeg( Rect rectangle, int quality, OutputStream stream)
Compress a rectangle region in the YuvImage to a jpeg.
int getHeight()
int[] getStrides()
int getWidth()
byte[] getYuvData()
int getYuvFormat()

释义:    

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/

	//@Override
	public 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();
             
         }
	}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值