Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><em>First</em> of all, you should avoid storing or transferring raw images to your phone; its always better to convert them to a compressed format such as PNG or JPG on your PC, and deploy that artwork to the device.</p> <p>However, if for some unusual reason you really want to load raw images, here is an approach:</p> <p>1) create an <code>Bitmap.Config.RGB_565</code> <a href="http://developer.android.com/reference/android/graphics/Bitmap.html" rel="noreferrer">bitmap</a> to contain your image. You must know the height and width of your raw image.</p> <p>2) create a <code>ByteBuffer</code> that is sufficient size to contain all the pixels in the bitmap; each <em>scanline</em> of the image takes a <em>stride</em> amount of pixels, which may be more than the image's width. This extra padding on each line is necessary. (Sometimes by happy coincidence the stride is the same as the width - there is no padding; this cannot be relied upon, always do your offsets taking account for stride.)</p> <p>With ByteBuffers, its important to understand the read and write offsets. After you've written to a ByteBuffer, you <a href="http://developer.android.com/reference/java/nio/Buffer.html#flip%28%29" rel="noreferrer"><code>flip</code></a> it to read those bytes.</p> <p>3) read the raw pixels from the file into your <code>ByteBuffer</code>, one scanline at a time, with the appropriate stride spacing between lines.</p> <p>4) use <a href="http://developer.android.com/reference/android/graphics/Bitmap.html#copyPixelsFromBuffer%28java.nio.Buffer%29" rel="noreferrer"><code>Bitmap.copyPixelsFromBuffer()</code></a>.</p> <p>5) discard the <code>ByteBuffer</code></p>
 

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