Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm working on exactly the same issue, but haven't got quite as far as you have.</p> <p>Have you considered drawing the pixels directly to the canvas without encoding them to JPEG first? Inside the OpenCV kit <a href="http://sourceforge.net/projects/opencvlibrary/files/opencv-android/2.3.1/OpenCV-2.3.1-android-bin.tar.bz2/download" rel="noreferrer">http://sourceforge.net/projects/opencvlibrary/files/opencv-android/2.3.1/OpenCV-2.3.1-android-bin.tar.bz2/download</a> (which doesn't actually use opencv; don't worry), there's a project called tutorial-0-androidcamera that demonstrates converting the YUV pixels to RGB and then writing them directly to a bitmap.</p> <p>The relevant code is essentially:</p> <pre><code>public void onPreviewFrame(byte[] data, Camera camera, int width, int height) { int frameSize = width*height; int[] rgba = new int[frameSize+1]; // Convert YUV to RGB for (int i = 0; i &lt; height; i++) for (int j = 0; j &lt; width; j++) { int y = (0xff &amp; ((int) data[i * width + j])); int u = (0xff &amp; ((int) data[frameSize + (i &gt;&gt; 1) * width + (j &amp; ~1) + 0])); int v = (0xff &amp; ((int) data[frameSize + (i &gt;&gt; 1) * width + (j &amp; ~1) + 1])); y = y &lt; 16 ? 16 : y; int r = Math.round(1.164f * (y - 16) + 1.596f * (v - 128)); int g = Math.round(1.164f * (y - 16) - 0.813f * (v - 128) - 0.391f * (u - 128)); int b = Math.round(1.164f * (y - 16) + 2.018f * (u - 128)); r = r &lt; 0 ? 0 : (r &gt; 255 ? 255 : r); g = g &lt; 0 ? 0 : (g &gt; 255 ? 255 : g); b = b &lt; 0 ? 0 : (b &gt; 255 ? 255 : b); rgba[i * width + j] = 0xff000000 + (b &lt;&lt; 16) + (g &lt;&lt; 8) + r; } Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); bmp.setPixels(rgba, 0/* offset */, width /* stride */, 0, 0, width, height); Canvas canvas = mHolder.lockCanvas(); if (canvas != null) { canvas.drawBitmap(bmp, (canvas.getWidth() - width) / 2, (canvas.getHeight() - height) / 2, null); mHolder.unlockCanvasAndPost(canvas); } else { Log.w(TAG, "Canvas is null!"); } bmp.recycle(); } </code></pre> <p>Of course you'd have to adapt it to meet your needs (ex. not allocating rgba each frame), but it might be a start. I'd love to see if it works for you or not -- i'm still fighting problems orthogonal to yours at the moment.</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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