12 messages in com.googlegroups.android-developersRe: [android-developers] Slow Bitmap ...
FromSent OnAttachments
saurabh30 Mar 2008 04:19 
David Given30 Mar 2008 07:07 
saurabh30 Mar 2008 10:09 
mickrobk30 Mar 2008 11:40 
ebs2...@gmail.com01 Apr 2008 11:02 
trickybit01 Apr 2008 15:01 
tomgibara01 Apr 2008 16:02 
saurabh02 Apr 2008 00:17 
qvark10 Apr 2008 15:30 
Romain Guy10 Apr 2008 15:34 
David Given10 Apr 2008 16:23 
qvark11 Apr 2008 00:10 
Subject:Re: [android-developers] Slow Bitmap operations
From:David Given (d.@cowlark.com)
Date:03/30/2008 07:07:56 AM
List:com.googlegroups.android-developers

This is an OpenPGP/MIME signed message (RFC 2440 and 3156)

saurabh wrote: [...]

The getPixel function seems to be taking approx 1/100 of a second. Similarly, checking whether each pixel satisfies the condition and then copying it to Bitmap B also takes approx 1/100 second. Therefore, performing these 2 operations for 547*450 = 246150 pixels takes a lot of time. Is there any way to do this faster?

I'd be inclined to copy all the pixel data out of the Bitmap into a int[] array of pixels; process it in-place; and then copy it all back in again. That way the heavy lifting --- the image processing --- occurs using simple array accesses, which should be way faster than doing method calls on Bitmap.

However...

I hope to use this for processing each frame of a video in real-time. So, processing each picture must not take more than a 1/20 of a second.

...not a chance!

Hopefully this will be improved considerably when the JIT goes in, but right now simply filling an array of the right size with zeroes takes over a second.

(I recently had to do something similar; I eventually got around it by pushing all the image processing off into native code via JNI, which of course is not officially supported and probably not a good choice unless you really need it.)