Rendering an iPhone UITabBar icon on BlackBerry

On the iPhone the correct way to make a UITabBar icon is to make a 32×32 image with just an Alpha channel. The iPhone will render the active icon using the “select” colour (blue) plus the alpha channel from the icon, and for the non-active icons it uses grey plus the alpha channel from the icon.

On the BlackBerry (Storm) the icons are generally displayed white on black. The following code will take the image data from the iPhone tab bar icon and render it in a BlackBerry style. It does this by setting every pixel to white whilst preserving the alpha channel from the icon.

// Convert raw (png) image data in DataBuffer to a bitmap.
Bitmap icon = Bitmap.createBitmapFromBytes(data.getArray(), 0, data.getLength(), 1);

// Extract the uncompressed image data into an array.
int w = icon.getWidth();
int h = icon.getHeight();
int l = w * h;
int[] raw = new int[l];
icon.getARGB(raw, 0, w, 0, 0, w, h);
		            
// Convert all pixels to white keeping original alpha
for (int i = 0; i < l; i++) {
	raw[i] = (raw[i] & 0xFF000000) + 0xFFFFFF;
}
		            
// Set the icon to this new version of the image.
icon.setARGB(raw, 0, w, 0, 0, w, h);
Advertisements

About austinfrance

Technical Developer @ RedSky IT / Explorer Software
This entry was posted in BlackBerry, Development, iPhone. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s