08-22-2012 05:41 AM - edited 08-22-2012 07:20 AM
Hi,
I have an templete image, and I want to apply it on an image. You can find below for illustration

+
= 
I want the white area in img1 will be transparent, and blue area will remain
What I want to achieve is to do the bitmap manipulation which will combine those 2 bitmap files into the final bitmap, not to draw it on the screen.
I've used the AdvancedUI sample code, which has alpha masking bitmap, but it does not solve my problem
Does anyone know how to do that? or have any sample code for that
Thanks alot for your help
08-22-2012 06:52 AM - edited 08-22-2012 06:54 AM
While there are a number of other options, as a start I suggest that you start developing this using a BitmapField and have two test images, one containing the image and one containing the template. The template will have the transparent part where you want it.
Now these should be the same size.
Create a BitmapField with the image you want. You need to extend this Field in two ways
1) Extend the BitmapField so that you have a setTemplate(bitmap template) method which remembers the template Bitmap. Say this saves it i n a local variable called _template.
2) Now override paint() in the BitmapField, so that it does the following:
super.paint(<graphics>);
<graphics>.drawBitmap(0, 0, this.getWidth(). this.getHeight(), _template, 0, 0);
This should get you started and demonstrate the basic processes. Once you have this working we can talk about other difficulties, like resizing the template, or changing the template. But get this working first.
And you do have to create the template image with the transparent part and make sure it is the same size as the image.
Edit:
Welcome to the forum!
08-22-2012 07:18 AM
Thanks for your response. However, what I want to achieve is to do the bitmap manipulation which will combine those 2 bitmap files into the final bitmap, not to draw it on the screen.
I've used the AdvancedUI sample code, which has alpha masking bitmap, but it does not solve my problem
08-22-2012 07:32 AM
08-22-2012 08:12 AM
08-22-2012 08:17 AM
08-22-2012 09:41 AM
08-22-2012 09:52 AM
08-22-2012 10:42 AM - edited 08-22-2012 10:44 AM
Going to change tack here.
The process I have described also works to paint the resultant image onto another Bitmap.
Assume you have a template and an image, and you want the transparent part of the template to show the corresponding part of the image.
Then you create a suitable size Bitmap, create Graphics context from that, paint the image onto that Graphics context and then paint the template.
The key parts of the code are
a) Creating the Bitmap - new Bitmap(...)
b) Getting the Graphics context. in OS 5.0 and above this is just
Graphics g = Graphics.create(<bitmap>);
c) Then two
g.drawBitmap( ...)
as before.
Now you have a combined Bitmap.
Apolgies, I missed the "not draw on Screen" comment in your first post.