安卓SDK之YUV-Image
生活随笔
收集整理的這篇文章主要介紹了
安卓SDK之YUV-Image
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?????? 類參考鏈接:http://api.apkbus.com/reference/android/graphics/YuvImage.html
1. 引入包: ??
?????? 安卓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.
參數
| The YUV data. In the case of more than one image plane, all the planes must be concatenated into a single byte array. |
| The YUV data format as defined in PixelFormat. |
| The width of the YuvImage. |
| The height of the YuvImage. |
| (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. |
拋出
| if 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();}}總結
以上是生活随笔為你收集整理的安卓SDK之YUV-Image的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: csgo旭日收藏品怎么掉
- 下一篇: WorkSpace介绍