如何通过Java编辑jpg图像? [英] How can I edit a jpg image through Java?
问题描述
我已经加载了一个jpg图像,我想在x,y坐标下绘制字母和圆圈。
I have loaded a jpg image in which I want to draw letters and circles, given a x,y coordinate.
我一直试图找出 ImageIcon class
I have been trying to figure out the paintIcon of the ImageIcon class
public void paintIcon(Component c,
Graphics g,
int x,
int y)
<这个方法是否允许我按照我想要的方式编辑jpg图像?什么是组件c和图形g参数?我会在它的身体上添加什么来画圆圈或字母?
Does this method allow me to edit jpg images the way I want to? What are supposd to be the Component c and Graphics g paramethers? What would I add to its body to paint circles or letters?
我正在使用Netbeans 6.5,我是否有内置任务(而不是ImageIcon)?
I'm working on Netbeans 6.5, do I have anything builtin for this task (instead of ImageIcon)?
推荐答案
纯Java方式是使用 ImageIO
到加载图像为 BufferedImage
。然后你可以打电话给 createGraphics()
获取 Graphics2D
对象;然后,您可以在图像上绘制任何想要的内容。
The pure-Java way is to use ImageIO
to load the image as a BufferedImage
. Then you can call createGraphics()
to get a Graphics2D
object; you can then draw whatever you want onto the image.
您可以使用嵌入在<$ c中的 ImageIcon
$ c> JLabel 进行显示,你可以添加 MouseListener
和/或 MouseMotionListener
到 JLabel
如果您试图允许用户编辑图像。
You can use an ImageIcon
embedded in a JLabel
to do the displaying, and you can add a MouseListener
and/or a MouseMotionListener
to the JLabel
if you're trying to allow the user to edit the image.
这篇关于如何通过Java编辑jpg图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!