11-20-2008 10:36 AM
11-20-2008 11:18 AM
I would suggest a subclass of FullScreen.
You can create the canvas like this:
Bitmap canvas = new Bitmap(Display.getWidth(),Display,getHeight())
Graphics g = Graphics.create(canvas)
Then use this Graphics object to do your painting on the canvas, and override the paint() method in your FullScreen to paint the canvas using drawBitmap()
...or something like that. Your mileage may vary.
11-20-2008 12:05 PM
The Bitmap option is a good one, and provides you with the ability to double buffer (multiple Bitmaps), which you might find useful. I think this is the official way.
One other possibility is to use:
Screen.getGraphics();
Here is the text from the javadoc.
public Graphics getGraphics()
Retrieves the graphics context for this screen.
This method returns the graphics context for this screen, with a clipping region on top of the graphics stack set to the screen's entire extent.
The Graphics object returned by this call becomes invalid and should not be used after the end of the current UI event.
Note: We recommend against direct use of this method; instead, use the various invalidate() methods. It may be used for direct drawing to the display when the screen contains no fields.
So this basically gives the same as the Bitmap, but you don't need to paint the bitmap onto the screen buffer, because you are doing it directly. I've tried this, it does seem to work, but have not used this in the wild yet. So, YMMV.
11-21-2008 03:34 AM
Ok, thanks both. Although BlackBerry, like most recent mobile phones, is double buffered so there's no need to perform your own buffering.
I miss an official explanation of this in manuals.
11-21-2008 04:04 AM
11-24-2008 03:37 AM
I'm trying the direct draw approach, but all I get is a blank screen.
Tried RexDoug Bitmap approach also, but this method:
Graphics g = Graphics.create(canvas);
doesn't seem to exist. I'm using OS 4.2.1
11-24-2008 04:50 AM
Ok, I have found two ways by now:
OPTION 1: Use a Bitmap and draw it in the overwritten paint() method:
import net.rim.device.api.system.Bitmap; import net.rim.device.api.ui.Graphics; import net.rim.device.api.ui.container.FullScreen; public class MyCanvas extends FullScreen { private Graphics canvas; private Main origen; private Bitmap bm; private int width, height; public MyCanvas(){ super(); width = Graphics.getScreenWidth(); height = Graphics.getScreenHeight(); bm = new Bitmap(width, height); canvas = new Graphics(bm); } public void paint(Graphics g){ //draw on canvas, for instance canvas.fillRect g.drawBitmap(0, 0, origen.width, origen.height, bm, 0, 0); } }
OPTION 2: why to use the bitmap?:
public void paint(Graphics g){ //draw directly on g }
And for those searching in manuals, where this issue is not covered, this link can also be useful:
The third option I tryed was to use Screen.getGraphics(), but is returning me a blank screen.
11-27-2008 04:40 PM
I'm new to BB developement. I trying to show a Field (obtained by calling : (Field)_video_controller.initDisplayMode(VideoCont
with a Bitmap (with transparency) on top of it.
Reading your post gave me some ideas... For example, I overrided the paint method of the FullScreen that contains the Field, like this :
public void paint(Graphics g){
super.paint(g);
g.drawBitmap(30, 30, _imageItems.getWidth(), _imageItems.getHeight(), _imageItems, 0, 0);
}
with this approach the bitmap is drawn order the Field. Any ideas of what I'm doing wrong ?
What would be the best way for painting layers ?
Thanks
11-27-2008 06:36 PM
Your call to super.paint() is delegated to all of the contained managers and fields; then you painted over top of the fields.
If you want a bitmap to be the background, override paintBackground() in your screen class. This is what it was designed for.
After paintBackground(), the other paint() methods will be hit and everything will paint over the background image.
See the API docs for class Screen.
08-10-2010 02:38 AM
Hi RexDoug,
I don't think you understood fred_sf correctly. I think what he wants is to make the bitmap(_imageItems) to appear on top of the video field. I want to do the same but after reading to some of the posts here, I think the API is not yet ready for this kind of layout.