Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid YuvImage class format incorrect?
    primarykey
    data
    text
    <p>It's well documented that Android's camera preview data is returned back in NV21 (YUV 420). 2.2 added a YuvImage class for decoding the data. The problem I've encountered is that the YuvImage class data appears corrupt or incorrect. I used the Renderscript Sample app called HelloCompute which transforms a Bitmap into a mono-chrome Bitmap. I used two methods for decoding the Preview data into a Bitmap and passing it as input to the Renderscript:</p> <p><strong>Method 1 - Android YuvImage Class:</strong></p> <p>YuvImage preview = new YuvImage(data, ImageFormat.NV21, width, height, null);</p> <p>ByteArrayOutputStream mJpegOutput = new ByteArrayOutputStream(data.length); </p> <p>preview.compressToJpeg(new Rect(0, 0, width, height), 100, mJpegOutput); mBitmapIn = BitmapFactory.decodeByteArray( mJpegOutput.toByteArray(), 0, mJpegOutput.size());</p> <p>// pass mBitmapIn to RS</p> <p><strong>Method 2 - Posted Decoder Method:</strong> As posted <a href="http://groups.google.com/group/android-developers/browse_thread/thread/c85e829ab209ceea/" rel="nofollow">over here by David Pearlman</a></p> <p>// work around for Yuv format </p> mBitmapIn = Bitmap.createBitmap( ImageUtil.decodeYUV420SP(data, width, height), width, height, Bitmap.Config.ARGB_8888);</p> <p>// pass mBitmapIn to RS</p> <p>When the image is processed by the Renderscript and displayed Method 1 is very grainy and not mono-chrome, while <em>Method 2 produces the expected output</em>, a mono-chrome image of the preview frame. Am I doing something wrong or is the YuvImage class not usable? I'm testing this on a Xoom running 3.1.</p> <p>Furthermore, I displayed the bitmaps produced by both methods on screen prior to passing to the RS. The bitmap from Method 1 has noticeable differences in lighting (I suspected this was due to the JPeg compression), while Method 2's bitmap is identical to the Preview Frame.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload