简体   繁体   English

如何从Java应用程序读取图像文件?

[英]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 , 看你以前的问题, 这个这个

  • you must know you're trying to read from current working directory (you can find it using System.getProperty("user.dir")) ) 您必须知道您正在尝试从当前工作目录中读取(可以使用System.getProperty("user.dir"))找到它)
  • It is not a webapp. 它不是一个webapp。
  • You cannot use shared (FTP) folders 您不能使用共享(FTP)文件夹

So, I can see 2 options: 因此,我可以看到2个选项:

  1. 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检查包含图像


  1. 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.

相关问题 如何从我的 Java 应用程序运行批处理文件? - How do I run a batch file from my Java Application? 如何从Web应用程序的根目录引用Java Web应用程序中的任何图像? - How do i refer to any image in my java web application from root of my web application? 如何从 Java 应用程序更新 JRE(或运行时映像)? - How do I update my JRE (or Runtime Image) from my Java application? 如何获取我的Hangman Java文件以从.txt文件中读取随机单词? - How do I get my Hangman Java file to read a random word in from a .txt file? 如何使我的Java程序从文本文件读取日语(Unicode编码)? - How do I get my java program to read Japanese (Unicode encoding) from a text file? 如何从 Java jar 文件中读取资源文件? - How do I read a resource file from a Java jar file? 如何在Java应用程序中添加文件浏览器? - How do I add a file browser inside my Java application? 在Java中,如何写入我最近读取的文件? - In Java, how do I write to a file I recently read from? 如何从我的 Java 应用程序与控制台应用程序交互? - How do I interact with a console application from my Java app? 如何使用 Java 从文件中增量读取行? - How do I use Java to incrementally read line from file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM