09-17-2009 01:33 AM
I'm trying to port an application from J2ME to the Blackberry API. I tried to use pushRegion to replace setClip from J2ME but it seems that these two methods behave different. I have an image with 7 buttons, one on top of another, each of them having a fixed height of 13 pixels, and the only different thing is their collor, each one is lighter than the previous one. I want to set the clip to draw a certain button, but the way that I use pushRegion is not correct and only a small piece is drawn sometimes, sometimes nothing is drawn. If I make pushRegion for the whole screen than all the image is drawn. Here is my code:
graphics.pushRegion(new XYRect(0, positionY, screenWidth, buttonHeight)); graphics.drawBitmap((screenWidth - buttonImage.getWidth()) / 2, positionY - buttonFrame[i] * buttonHeight, buttonImage.getWidth(), buttonImage.getHeight(), buttonImage, 0, 0); graphics.popContext();
Should I use pushContext instead of pushRegion
And one more problem: after several drawings ( I make the drawing in a for loop) I get "out of memory" error on the emulator, I suppose it's because of the pushRegion and popContext because I don't create other objects.
Solved! Go to Solution.
04-04-2010 04:55 PM - edited 04-04-2010 05:32 PM
- Both of them update the clipping regions:
The clipping region is updated by intersecting with the previous clipping region.
- Use popContext() for both of them.
- (1) The orgin of coordinate ORG is set to (xOffset,yOffset)
- (2) ORG is set to (left,top) of r
- (3) ORG is set to (left,top) of r and then set traslation of coordinate to (xScroll,yScroll)
In order to understand, imaging that you want to change the clipping region to an area (for example a Manager of object with VERTICAL_SCROLL | HORIZONTAL_SCROLL style) and this area has been scrolled (in our example the virtual extent of manager is larger than the physical extent and user has call setVerticalExtent/setHorizontalExtnet). In this case, use SHOULD use (3).
You can find an example at
08-07-2011 07:33 PM - edited 08-07-2011 07:34 PM
I actually found "Manage_a_drawing_area_508101_11.jsp" pretty useless because it contained no diagrams to show you what was happening. It does give code examples for using the two and uses about the same verbage given in the API spec, which led me to search for a clearer definition and diagrams..
After my ump-teenth reading of that document I still don't know when to use pushRegion and when to use pushContext. I always end up trying one and then trying the other if it didn't do what I needed. A few pictures of the results would help.
Here I am again...