Reputation: 59
Plz explain briefly with examples the meaning of
public void drawBitmap(int x,
int y,
int width,
int height,
Bitmap bitmap,
int left,
int top)
Use this method to draw a bitmap. You specify the destination region
for the bitmap by describing the **extent** of the region
with passed parameters.
(Ques 1) Plz explain clearly what is mean by extent of the region
(Ques 2)
x - Left edge of the destination region.
y - Top edge of the destination region.
left - Left edge of region within bitmap to draw.
top - Top edge of region within bitmap to draw.
I have confusion in in x, y, left, top. Suppose i want to draw a picture in the left of the custombutton. and my
protected void paint(Graphics graphics)
{
graphics.setColor(Color.RED);
graphics.fillRoundRect(1, 1, getWidth()-2, getHeight()-2, 12, 12);
int ph = onPicture.getHeight();
graphics.drawBitmap(0, 0, getWidth(), getHeight(), onPicture, 0, 0);
graphics.setColor(Color.GREENYELLOW);
int x = (bw/2 - labelWidth/2);
int y = (bh/2 - labelHeight/2);
graphics.drawText(label, x, 8);
}
Actually my problem is if i write
graphics.drawBitmap(0, 0, getWidth(), getHeight(), onPicture, 10, 0);
instead of
graphics.drawBitmap(0, 0, getWidth(), getHeight(), onPicture, 0, 0);
it gives a error."source code not found" And according to my concept x, y, getPrefferedheight(), getPrefferedWidth gives the region within the custom button within which the created bitmap can be drawn and accordingly i set the value 10 instead of 0, but it gives error source code not found..... Can anybody help me what is wrong in my concept.
Upvotes: 2
Views: 176
Reputation: 1809
The easiest way to think of it is that drawBitmap only allows you to draw a section of the bitmap. The parameters specify the rectangle that you wish to draw to, and the rectangle you wish to copy from within the bitmap. So the extent of the region means the width and height of the area that you will be drawing, and is specified by the width
and height
parameters. x
and y
specify the coordinates you want to draw to, and left
and top
specify the upper left coordinates within the bitmap image that you want to copy. That means that
graphics.drawBitmap(0, 0, getWidth(), getHeight(), onPicture, 10, 0);
will take part of the bitmap and draw it to the upper-left of your destination graphics object (the graphics object in this context is just the place that you are painting to, that will be displayed on the screen). The left 10 pixels of the bitmap will not be drawn, and the area that will be drawn will be getWidth()
wide and getHeight()
high. By contrast,
graphics.drawBitmap(0, 0, getWidth(), getHeight(), onPicture, 0, 0);
will draw at the same position and same size, but will not cut off the left 10 pixels of the bitmap (it will stop copying the bitmap 10 pixels earlier on the right side instead).
That said, I don't think this call is really what is causing the error you are seeing. If you are getting a "source code not found" error, then it is most likely a problem with updating the code on the blackberry after you made a change. This can usually be rectified by doing a clean build. In some situations, you may even have to reset the simulator. You can do this by opening a command prompt, going to the simulator folder (in <eclipse dir>/plugins/net.rim.ejde.componentpack.../components/simulator
) and running clean.bat
Upvotes: 4
Reputation: 2073
briefly i can explain like this. if you want your icon like this, you must set left
and top
"0".
Upvotes: 3