使用 JFreeChart 库在 awt.Image 上绘制轴
我有一个类需要能够接收图像并添加一组轴。我不想自己编写代码,而宁愿偷懒并利用 JFreeChart 库。
这是我到目前为止所拥有的,据我所知,它没有做任何事情:
public void addAxis(Image sourceImage, double min, double max)
{
NumberAxis numAxis = new NumberAxis();
numAxis.setRange(min, max);
int width = sourceImage.getWidth(null);
int height = sourceImage.getHeight(null);
Rectangle2D size = new Rectangle(width, height);
Graphics2D graphics = (Graphics2D) sourceImage.getGraphics();
numAxis.draw(graphics, 0, size, size, RectangleEdge.LEFT, null);
return;
}
我传递给它的 Image
是使用 BufferedImage
创建的代码>TYPE_INT_ARGB。
可能还有其他更适合此目的的库,但不幸的是,很难获得批准将库添加到我的项目中,而 JFreeChart 已经获得批准。为了其他读者的利益,请随意提及替代库。
编辑:由于各种原因,我需要在图像上绘制轴,我无法在图表上绘制图像或执行任何会改变其大小的操作。
I have a class that needs to be able to take in an image and add a set of axis. I don't feel like writing out the code myself and would rather be lazy and utilize the JFreeChart library.
Here's what I have so far, which isn't doing anything as far as I can tell:
public void addAxis(Image sourceImage, double min, double max)
{
NumberAxis numAxis = new NumberAxis();
numAxis.setRange(min, max);
int width = sourceImage.getWidth(null);
int height = sourceImage.getHeight(null);
Rectangle2D size = new Rectangle(width, height);
Graphics2D graphics = (Graphics2D) sourceImage.getGraphics();
numAxis.draw(graphics, 0, size, size, RectangleEdge.LEFT, null);
return;
}
The Image
that I'm passing into it is created as a BufferedImage
using TYPE_INT_ARGB
.
There may be other libraries that are better suited for this, but unfortunately it is difficult to get approval to add a library to my project and JFreeChart is already approved. Please feel free to mention alternative libraries anyways for the benefit of other readers.
Edit: for various reasons, I need to draw the axis on the image, I cannot draw the image on a chart or do anything that would change it's size.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
想通了,为任何想做同样事情的人发帖。
该线
应该是
否则轴将从图像中绘制出来。我没有弄清楚这一点(我正在为此而自责),因为轴正在获取我在图形对象上使用的最后一种颜色,而该颜色恰好正在绘制背景。
Figured it out, posting for anyone who wants to do the same thing.
The line
should be
Otherwise the axis is drawn off the image. I didn't figure this out (and I'm kicking myself for this one) because the axis was getting the last color I'd used on the graphics object, which happened to be drawing the background.