drawLine 不会在 BufferedImage 上绘制线条
我有以下问题。我想在 BufferedImage 上画线,但它们没有显示。如果我不加载图像,它们就会显示。问题是什么?这是我的代码:
@Override
public void paintComponent(Graphics g) {
prepareImage();
g.drawImage(buffer, 0, 0, null);
g.dispose();
}
private void prepareImage() {
Graphics g = buffer.createGraphics();
g.drawImage(mapImage, 0, 0, null);
g.setColor(Color.RED);
for (Line line : lines)
g.drawLine(line.x1, line.y1, line.x2, line.y2);
lines.clear();
g.dispose();
}
感谢您的帮助。
I've got a following problem. I want to draw lines over BufferedImage, but they don't show up. If i don't load the image, they will show. What is the problem? Here is my code:
@Override
public void paintComponent(Graphics g) {
prepareImage();
g.drawImage(buffer, 0, 0, null);
g.dispose();
}
private void prepareImage() {
Graphics g = buffer.createGraphics();
g.drawImage(mapImage, 0, 0, null);
g.setColor(Color.RED);
for (Line line : lines)
g.drawLine(line.x1, line.y1, line.x2, line.y2);
lines.clear();
g.dispose();
}
Thanks for help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在您的代码中看到两个问题:
I see two issues in your code: