Java图形图像 [英] Java graphic image

查看:100
本文介绍了Java图形图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿我在Jpanel中添加以下图片: msu-footprints.org/2011 /Aditya/map.jpg

Hey I am adding the following image in the Jpanel: msu-footprints.org/2011/Aditya/map.jpg

然后添加多边形

int[] x = new int[]{65, 122, 77, 20}; 
int[] y = new int[]{226, 258, 341, 310}; 
g.setColor(Color.RED); 
g.drawPolygon(x, y, x.length); 

多边形应与建筑物GER重合,但有点偏移。我的专业说,坐标是可以的。如何放置图像位置有什么问题吗? -

The polygon should coincide with building GER but is a little bit offset. My proff says the co-ordinates are okay. Is there anything wrong with how I put the image position? –

推荐答案

如果直接绘制到顶级容器(JFrame),那么
坐标空间将是错误的,考虑到框架的边框和菜单栏,内容窗格实际上是
偏移。

If painting directly to the top level container (JFrame), then the coordinate space will be wrong, the content pane is actually offset, taking into account the frame's border and menu bar.

如果覆盖任何框架的<$ c $,就会出现这种情况。 c> paint 方法或使用 getGraphics 方法。

This will occur if you override any of the frame's paint methods OR use the getGraphics method.

创建自定义组件(从 JPanel 扩展)并覆盖它的 paintComponent 方法并直接将图像和矩形渲染到它。坐标空间将是正确的(顶部,左角将是0x0)

Create a custom component (extending from something like JPanel) and override it's paintComponent method and render the image and rectangle directly to it. The coordinate space will then be correct (top, left corner will be 0x0)

这篇关于Java图形图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆