Fastest way to draw an int[] to a SurfaceHolder/Canvas

by Daniel 脜kerud » Thu, 15 Apr 2010 00:23:59 GMT


Sponsored Links
 Hello!

I'm developing a Live Wallpaper and am currently looking into
optimizing the drawing part. I have a precalculated int[] of colors
and need to deliver this to the screen. The fastest way I have found
up to now is this:

  int[] pixels = new int[surfaceWidth * surfaceHeight];
  IntBuffer pixelBuffer = IntBuffer.wrap(pixels);
  bitmap = Bitmap.createBitmap(surfaceWidth, surfaceHeight,
Config.ARGB_8888);

  // when updates to "pixels" are done, I just blit it to the canvas
like this:
  canvas = getSurfaceHolder().lockCanvas();
  bitmap.copyPixelsFromBuffer(pixelBuffer);
  canvas.drawBitmap(mBitmap, 0, 0, null);
  holder.unlockCanvasAndPost(c);

The extra intermediate copying onto the bitmap seems redundant and I
was hoping to get rid of it. Canvas.drawBitmap(int[], ...) looks on
the surface to do the trick but is surprisingly a few ms slower.
Digging into the source code reveals that it also makes a complete
copy of the data onto a Bitmap before drawing. I have tried updating
the Bitmap directly but it has proven much slower due to the many
method calls needed.

Is there a faster way to get the int[] onto the surface?

Thanks,
apan

--



Other Threads

1. How to debug native code in eclipse

Hi,
I created one android application it is using one native method.
I created shared library using ndk tools.My jni function is having some
problems i want to
debug it.
How to debug it in eclipse tool

-- 

2. WCBS Radio

HI - One application I miss from my old IPhone is AOLRadio
It had the New York City AM news radio stations - WCBS880 and WINS-1010
Does anyone know of an Android app that gets those stations?
Thanks, Victor

(PS - I still carry around my old IPhone just for that and Kindle, which
still work with WI-FI)

-- 

3. Google Directions status?

4. SQLiteCursor on that has not been deactivated or closed

5. Wi-Fi driver not working with changed Kernel

6. how to rotate quad around its center

7. Alternatives to static variables in Android