Blackberry 中的类图形
请举例简要解释(问题 1)的含义
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.
请清楚地解释区域范围的含义
(问题 2)
x - 目标区域的左边缘。
y - 目标区域的上边缘。
left - 位图中要绘制的区域的左边缘。
top - 位图中要绘制的区域的上边缘。
我对 x、y、左、上感到困惑。 假设我想在自定义按钮的左侧画一张图片。 实际上我
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);
}
的问题是如果我写
graphics.drawBitmap(0, 0, getWidth(), getHeight(), onPicture, 10, 0);
而不是
graphics.drawBitmap(0, 0, getWidth(), getHeight(), onPicture, 0, 0);
它会给出错误。“未找到源代码” 根据我的概念 x, y, getPreferedheight(), getPreferedWidth 给出了自定义按钮内可以绘制创建的位图的区域,因此我将值设置为 10 而不是 0,但它给出了错误源代码未找到。 ... 谁能帮助我我的概念有什么问题。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单的想法是,drawBitmap 只允许您绘制位图的一部分。这些参数指定您希望绘制到的矩形,以及您希望从位图中复制的矩形。因此,区域的范围意味着您将绘制的区域的宽度和高度,并由
width
和height
参数指定。x
和y
指定要绘制到的坐标,left
和top
指定范围内的左上角坐标您要复制的位图图像。这意味着它将获取位图的一部分并将其绘制到目标图形对象的左上角(此上下文中的图形对象只是您要绘制的位置,它将显示在屏幕上)。位图的左边 10 个像素将不会被绘制,并且将绘制的区域将为
getWidth()
宽和getHeight()
高。相比之下,将在相同的位置和相同的大小处绘制,但不会切断位图的左侧 10 个像素(它将停止在右侧提前 10 个像素复制位图)。
也就是说,我认为这个调用并不是真正导致您所看到的错误的原因。如果您收到“未找到源代码”错误,则很可能是在进行更改后更新黑莓上的代码时出现问题。这通常可以通过执行干净构建来纠正。在某些情况下,您甚至可能需要重置模拟器。您可以通过打开命令提示符,转到模拟器文件夹(在
/plugins/net.rim.ejde.componentpack.../components/simulator
中)并运行 <代码>clean.batThe 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
andheight
parameters.x
andy
specify the coordinates you want to draw to, andleft
andtop
specify the upper left coordinates within the bitmap image that you want to copy. That means thatwill 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 andgetHeight()
high. By contrast,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 runningclean.bat
我可以简单地解释一下。如果你想要这样的图标,你必须将
left
和top
设置为“0”。briefly i can explain like this. if you want your icon like this, you must set
left
andtop
"0".