I have stored an image in a Resource folder 'Images':
src
-com.program
-Images
In the program I use
BufferedImage image =ImageIO.read(getClass().getResourceAsStream("/myImage.png"));
to import the image.
This works fine. However, if i change the name of the image at the source(say to myImage1.png)
and try to execute
BufferedImage image =ImageIO.read(getClass().getResourceAsStream("/myImage1.png"));
I get Input==Null.
I've been try to get this to work for a while and tried various suggestions on other threads.
Any ideas?
Thanks!
The problem was most likely:
The image was in your src folder inside your project, but when the program runs, it runs from another folder containing your compiled classes. This folder did not contain the png, so you get the input == null exception (getClass().getResourceAsStream(...) returns null when resources cannot be resolved).
To make it work, you need to mark the images folder a resource folder (using Eclipse, Maven or favorite build tool), and make sure that the contents of that folder is on your class path when the program is run.
Related
I am not able to access folder from Downloads folder to MATLAB online version and even if I make folder of images in MATLAB online, even then it is not accessing.
I have 20 images in my folder and want to make all of them read in a variable (struct variable with fields) in MATLAB online compiler
Actually I have a folder of images in Downloads folder and want to access it in MATLAB online version, but not able to do it. I tried:
images=dir('C:\Users..........\im_patching\data_10pair')
By using breakpoints, it is seen that it is not storing any name and description of images.
It is giving : 0*1 empty struct array with fields name, folder, date, bytes, isdir, datenum
and Secondly, if I make the folder inside the MATLAB online version only and access it like
eg. Path to the images in matlab online compiler is
/MATLAB Drive/2017_CNN/patching/data_10pair/a.jpg.... (all 20 images)
now to access all the images a.jpg, b.jpg......
the MATLAB code line is
images = /2017_CNN/patching/data_10pair
after applying breakpoints it gives : 1*29 char
I want to make the "images" variable read all the names of images with the fields
My folder has 20 images.
Kindly help, I am new to MATLAB.
I'm using the Object Manager in order to add a few products from a csv (based on https://magecomp.com/blog/import-product-data-programmatically-magento-2/ ). So far everything is working and my images are temporarily stored in "var/tempImages/". When I pass that path into:
//$img is my path to "product.jpg", etc.
->setImage($img)
->setSmallImage($img)
->setThumbnail($img)
Images are not loading at all (doubled checked, they're in said path).
Any pointers on what could be missing to correctly map the path to image (or if I'm in something completely different).
Thanks.
I work with a multi-root workspace in VS Code. Here's my folder structure:
project-one
-node_modules
-public
--css
---styles.css
--img
---global
-----logo.svg
--js
---main.js
--index.html
project-two
project-three
When I reference files in my index.html file, VS Code always wants me to write it like this (in index.html):
src="img/global/logo.svg"
That doesn't really make sense to me. Logically, I would write the relative path to the logo with a leading / before img as the img folder is at the same level as index.html. However, that doesn't work.
Can anybody explain me why? And will the path declarations work correctly like this when I upload these files to the server (the content of the public folder will then be at the root)?
Thanks.
I have a project with a image stored as a logo that I wish to use.
URL logoPath = new MainApplication().getClass().getClassLoader().getResource("img/logo.jpg");
Using that method I get the URL for the file and convert it to string. I then have to substring that by 5 to get rid of this output "file:/C:/Users/Stephen/git/ILLA/PoC/bin/img/logo.jpg"
However when I export this as a jar and run it I run into trouble. The URL now reads /ILLA.jar!/ and my image is just blank. I have a gut feeling that it's tripping me up so how do I fix this?
Cheers
You are almost there.
Images in a jar are treated as resources. You need to refer to them using the classpath
Just use getClass().getResource: something like:
getClass().getResource("/images/logo.jpg"));
where "images" is a package inside the jar file, with the path as above
see the leading / in the call - this will help accessing the path correctly (using absolute instead of relative). Just make sure the path is correct
Also see:
How to includes all images in jar file using eclipse
See here: Create a file object from a resource path to an image in a jar file
String imgName = "/resources/images/image.jpg";
InputStream in = getClass().getResourceAsStream(imgName);
ImageIcon img = new ImageIcon(ImageIO.read(in));
Note it looks like you need to use a stream for a resource inside an archive.
i m creating a project in gwt (point) is project name ...
i want to store a image in point/war/images folder, whaich i gave the full path like C:\Documents and Settings\computer\workspace\m\war\images\ tthe the iamge will stored in images folder but i want to give the default path
i give "../war/images/" as default path, but this give me error (he system cannot find the path specified )
can any body help to give the default path
Usually you put images in the war/images directory, and you access them like
Image img = new Image("images/my_image.jpg")
You may also read this thread, and this question.