[英]How do i read an image file from my java application?
i have developed an invoice generate program. 我已经开发了发票生成程序。 each pdf invoice include an image on top left corner, when i run the application on someone else's machine(not the developed machine), it doesn't show the image on top left corner of the pdf.
每个pdf发票的左上角都包含一个图像,当我在其他人的机器(不是已开发的机器)上运行应用程序时,它不会在pdf的左上角显示图像。
this is how I read the image: 这是我阅读图像的方式:
Image companyLogo = Image.getInstance("images/amadeus14.png");
This is my option 1 这是我的选择1
within the project i have created a package and inside it i have made a folder called image. 在项目中,我创建了一个程序包,并在其中创建了一个名为image的文件夹。 inside that folder i have put that image file and tried to access it in my program.
在该文件夹中,我已将该图像文件放入并尝试在程序中访问它。
Image companyLogo = Image.getInstance("Resources/Images/HemasLogo.jpg");
this is my option 2 option 这是我的选择2
but it gives an error saying 但它给出了一个错误的说法
java.io.FileNotFoundException: C:\\Users\\businesssupport\\Documents\\NetBeansProjects\\invoiceGenerator\\Resources\\HemasLogo.jpg (The system cannot find the path specified) java.io.FileNotFoundException:C:\\ Users \\ businesssupport \\ Documents \\ NetBeansProjects \\ invoiceGenerator \\ Resources \\ HemasLogo.jpg(系统找不到指定的路径)
Looking at your previous questions this and this , 看你以前的问题, 这个和这个 ,
System.getProperty("user.dir"))
) System.getProperty("user.dir"))
找到它) So, I can see 2 options: 因此,我可以看到2个选项:
to put the image inside a package before packing the application, then you will be able to read it from any computer without making any changes 在打包应用程序之前将图像放入包装中,然后您就可以从任何计算机上读取图像而无需进行任何更改
Check Including Images with an executable jar 使用可执行jar检查包含图像
Use a local folder. 使用本地文件夹。 You will need to create a common folder for each installed computer, then manually copy the image on each computer, and read it like
您将需要为每台已安装的计算机创建一个公用文件夹,然后在每台计算机上手动复制图像,然后像读取图像一样
Image companyLogo = Image.getInstance("C:\\\\myApp\\\\images\\\\amadeus14.png");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.