本文介绍了Java:从文件加载图像,编辑并添加到JPanel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将计算机中的图像加载到2D图形中,以便我可以在之后编辑它,然后我想将其添加到 JPanel
。如果您需要查看我的项目,我可以将其发送给您。
I want to load an image from my computer into 2D Graphics so that I can edit it afterwards and then I want to add it to JPanel
. If you need to see my project I can send it to you.
void loadImage()
{
FileDialog fd = new FileDialog(new Frame(), "Please choose a file:", FileDialog.LOAD);
fd.show();
if (fd.getFile() != null)
{
File fil = new File(fd.getDirectory(), fd.getFile());
strDirectory = fd.getDirectory();
strFileType = fd.getFile();
mainImage.setIcon(new ImageIcon(fil.toString()));
getFileList(strDirectory);
checkFileType(strFileType);
}
}
提前致谢
推荐答案
请阅读本教程关于,你的Image / ImageIcon将被放置到,这种方式消除了油漆/油漆组件的所有麻烦......
please read this tutorials about Icon in Swing and your Image/ImageIcon would by placed to the JLabel, this way eliminated all troubles came from paint/paintComponents ...
这篇关于Java:从文件加载图像,编辑并添加到JPanel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!