Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 16
Registered: ‎07-30-2012
My Device: None
My Carrier: Proximus

Draw a bitmap on a bitmap

[ Edited ]

Hi,

 

I have drawn a bitmap on a bitmap and placed it in a bitmapfield. Now how do I save this bitmap on bitmap as one image? 

 

package mypackage;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.container.MainScreen;

public class BitmapFieldDemo extends UiApplication 
{
    public static void main(String[] args)
    {
        BitmapFieldDemo theApp = new BitmapFieldDemo(); 
        theApp.enterEventDispatcher(); 
    }

    public BitmapFieldDemo() 
    { 
        pushScreen(new BitmapFieldDemoScreen()); 
    } 
}

class BitmapFieldDemoScreen extends MainScreen
{
    Graphics g;
    Bitmap bitmapImage = Bitmap.getBitmapResource("red.png");
    Bitmap bitmapImage2 = Bitmap.getBitmapResource("field.png");

    public BitmapFieldDemoScreen ()
    {
    	g =  Graphics.create(bitmapImage);
        BitmapField bField = new BitmapField(bitmapImage);
        add(bField);
        

    }

    public void paint( Graphics s){
    	super.paint(s);
    	
    	s.drawBitmap(0, 0, 50, 50, bitmapImage2, 0, 0);
    }

}

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Draw a bitmap on a bitmap

You seem to keep starting new Threads for questions that appear to be related to previous Threads, for example, this question seems like a continuation of

http://supportforums.blackberry.com/t5/Java-Development/ZoomScreen-with-image-and-bitmap/td-p/184160...

which is a similar question t this:

http://supportforums.blackberry.com/t5/Java-Development/Draw-Bitmap-on-Encoded-Image/m-p/1839725

and this:

http://supportforums.blackberry.com/t5/Java-Development/Bitmap-amp-Zoomscreen/m-p/1838449

 

Can I suggest that you just add information to an existing Thread if it is related?  And if it is not related and you don't need to continue a Thread, then can you please mark it as solved - instructions in the Help link near the top of the screen.

 

Anyway, you have not actually drawn on the Bitmap, you have actually just painted the screen with two Bitmaps.

 

To draw on a Bitmap, you must first create a Graphics Object using the Bitmap.  Then you can paint on the Graphics Object.  The appropriate method to create a Graphics Object using a Bitmap as the canvas depends on OS level, for OS 5.0  if is Graphics.create(<bitmap>).

 

Then once you have the Bitmap you want, you need to convert it back to an EncodedImage,  EncodedImage is just a common class for all the supported Image types, so you need to create one of the real types, say PNGEncodedImage, which you can do just using

PNGEncodedImage.encode(<bitmap>);

 

Job done I think!

Contributor
Posts: 16
Registered: ‎07-30-2012
My Device: None
My Carrier: Proximus

Re: Draw a bitmap on a bitmap

I created the Graphics.create(<bitmap>) in the sample, but is it in the right place?

Highlighted
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Draw a bitmap on a bitmap

You did, but you never used it. 

 

Try something like the following and see:

 

After

 

g =  Graphics.create(bitmapImage);

 

add

 

g.setColor(0x00FF0000);

g.fillRect(0,0,10,10);

 

Coded entirely from my suspect memory, you get the idea, please correct the syntax.

 

Good luck.