Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you are going to be manipulating every multiple pixels you could call <a href="http://developer.android.com/reference/android/graphics/Bitmap.html#getPixels%28int%5B%5D,%20int,%20int,%20int,%20int,%20int,%20int%29" rel="nofollow">getPixels()</a> and <a href="http://developer.android.com/reference/android/graphics/Bitmap.html#setPixels%28int%5B%5D,%20int,%20int,%20int,%20int,%20int,%20int%29" rel="nofollow">setPixels()</a> to get them all at once. This will prevent additional method calls and memory references in your loop.</p> <p>Another thing you could do is do the pixel addition with bitwise or instead of the helper methods. Preventing method calls should increase efficiency:</p> <pre><code>public static void applyAlpha(Bitmap b, Bitmap bAlpha) { int w = b.getWidth(); int h = b.getHeight(); int[] colorPixels = new int[w*h]; int[] alphaPixels = new int[w*h]; b.getPixels(colorPixels, 0, w, 0, 0, w, h); bAlpha.getPixels(alphaPixels, 0, w, 0, 0, w, h); for(int j = 0; j &lt; colorPixels.length;j++){ colorPixels[j] = alphaPixels[j] | (0x00FFFFFF &amp; colorPixels[j]); } b.setPixels(colorPixels, 0, w, 0, 0, w, h); } </code></pre> <p>That being said the process you are trying to undertake is fairly simple, I can't imagine these will provide a huge performance boost. From this point the only suggestion I can provide would be to goto a native implementation with the <a href="http://developer.android.com/tools/sdk/ndk/index.html" rel="nofollow">NDK</a>.</p> <p><strong>EDIT:</strong> Also since a Bitmap doesn't have to be mutable to use <code>getPixels()</code> or <code>getPixel()</code> you can get the alpha bitmap with <a href="http://developer.android.com/reference/android/graphics/BitmapFactory.html#decodeResource%28android.content.res.Resources,%20int%29" rel="nofollow">BitmapFactory.decodeResource()</a>:</p> <pre><code>Bitmap ba = BitmapFactory.decodeResource(a.getResources(), alphaImgId); </code></pre>
    singulars
    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. 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