[英]Can't get a image from resources
I have problem to get an image from another package of my Eclipse project!我在从 Eclipse 项目的另一个包中获取图像时遇到问题! I saw this post here My code is this CreateTableOnPDF.java:我在这里看到这篇文章我的代码是这个 CreateTableOnPDF.java:
288 ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
289 InputStream input = classLoader.getResourceAsStream("images/sun.png");
290 PDJpeg img = new PDJpeg(doc, input);
I getting this exception:我收到此异常:
Exception in thread "main" java.lang.IllegalStateException:
at org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg.setPropertiesFromAWT(PDJpeg.java:132)
at org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg.<init>(PDJpeg.java:113)
at MainClasses.CreateTableOnPDF.main(CreateTableOnPDF.java:290)
I don't know what I am doing wrong?我不知道我做错了什么? Maybe is the a lot hour a have spend already infront of my monitor.也许是我的显示器前已经花了很多时间。
Here is my project structure:这是我的项目结构:
Thanks for your attention and time!感谢您的关注和时间!
Please check the API docs, you should put JPEG data, not PNG data.请检查API文档,您应该放置 JPEG 数据,而不是PNG 数据。
public PDJpeg(PDDocument doc, InputStream is) throws IOException
Parameters:参数:
doc
- The document to create the image as part of. doc
- 作为其一部分创建图像的文档。is
- The stream that contains the JPEG data. is
- 包含 JPEG 数据的流。Throws:抛出:
IOException
- If there is an error reading the JPEG data. IOException
- 如果读取 JPEG 数据时出错。Are you getting input
as null
?你的input
是null
吗? If so try the path as "../images/sun.png"
如果是这样,请尝试将路径设为"../images/sun.png"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.