Cannot show local images - java

I am using GWT and I am using Image Widget to view an image. This image is located in my file system.
I wrote the following line of code:
String src = "file:///D:/myfolder/myfile.jpg";
Image image = new Image();
image.setUrl(src);
Please note I need to show only local images; not from the server. It may sound strange but I need to show from the client machine. Assume all clients will have same image and same path.
Thanks.

I believe that what are you trying is not possible due to "Same Origin Policy" in browsers: Same Origin Policy Wikipedia article.

It's very unusual that you have to specify full path with drive name.
There are many ways to get your context path and then make the path relative to it.
I've just tried to setUrl to the GWT's Image in your way. Everything was fine.
Try to check your path, image extension etc.
Maybe your do something wrong when add image to the layout?

Related

Wants to get thumbnail of files except images in liferay

I want to get the thumbnail of all Files stored in Document and Media portlet of Liferay ,for images thumbnails i am using these libraries
import com.liferay.portlet.documentlibrary.util.ImageProcessorUtil;
import com.liferay.portlet.documentlibrary.util.DLPreviewableProcessor;
and for getting thumbnail stream i am using this mechanism
InputStream thumbnail = ImageProcessorUtil.getThumbnailAsStream(f.getFileVersion(), DLPreviewableProcessor.THUMBNAIL_INDEX_DEFAULT);
My problem is that i want to get the thumbnail stream of all contents stored in Liferay.Is is possible??? any help will be greatly appreciated.
This functionality is already provided by Liferay. As the documentation suggests, you will need to configure some 3rd party tools/libraries on your Liferay instance.
If you just want to change the default thumbnail images, then you can update your replace these images with the images of your choice at _unstyled\images\file_system\large and _unstyled\images\file_system\small in your theme.
EDIT
To answer your last comment about previewing XML file (which I have answered on high level above, but nevertheless...):
Add the below property in your portal-ext.properties file:
dl.file.generic.extensions[xmlimage]=xml
And, add xmlimage.png file in _unstyled\images\file_system\large
and _unstyled\images\file_system\small in your theme.

How to use Image in JRadioButtons instead of text

I have a group of JRadioButtons. I want to use image instead of text in my JRadioButtons. So I believe i will have to use this:
JRadioButton(Icon icon, boolean selected)
Now the issue is that I am not sure about how to create this icon. I have the image that I want to use and I have copied the image in my source code folder. It is in .tiff format. i want to read that .tiff image (inputStream I believe) and convert that to icon so that i can have my JRadioButtons.
Please help in implementing this.
Thanks in advance.
Assuming you put the image in your source folder, in the package com.foo.bar, and that your build process copies this file with your classes so that it's in the classpath when running the application (that's what all IDEs do by default), you can just use
new ImageIcon(MyClass.class.getResource("/com/foo/bar/MyImage.png"))
to get you an icon.
I'm not sure that Java has native support for the tiff format, so you might have to convert the image to another supported format to load it (gif, JPEG and PNG will work fine).
If you're getting a NullPointerException, it probably means that the image is not at the path you're indicating.
You said you stuck it right into the src folder so this should work:
new ImageIcon(getClass().getResource("icon.jpg"))

java.lang.reflect.InvocationTargetException

I have an applet with some buttons in it, the buttons have image icons. I also have made an HTML file with this applet. Whenever I open this page from server (Apache tomcat) an exception occurs:
java.lang.reflect.InvocationTargetException.
But if I run without the icons, there are no problems. Can anyone help me, so that I can load the applet with the button icons?
Image myImage = getToolkit().createImage("image/REC1.jpg");
ImageIcon myIcon = new ImageIcon(myImage);
button.setIcon(myIcon);
Toolkit.createImage(String):
Returns an image which gets pixel data from the specified file. The returned Image is a new object which will not be shared with any other caller of this method or its getImage variant.
This method first checks if there is a security manager installed. If so, the method calls the security manager's checkRead method with the specified file to ensure that the image creation is allowed.
I made 2 parts bold:
File - only ever points to the local file-system of the computer on which the applet is running. So are unsuitable for icons in the applet - they must be on the server. And..
Security Manager - which will not allow a sand-boxed applets to read or write to the local file-system. That might be the important part of the stack trace that is missing.
Applet resource access
Applets need to load resources from the 'home server' if sand-boxed, by URL.
The icons might be an embedded resource, inside a Jar referenced in the archive attribute of the applet element, but if they are loaded to the server as images, they can be accessed relative to the document base or code base. Here is what it might look like for an image named REC1.jpg in the image sub-directory of the directory that contains the HTML.
URL url = new URL(getDocumentBase(), "image/REC1.jpg");
Image myImage = getToolkit().createImage(url);
you can use .PNG file format also. and used small letter for file name.

How to load an image to java application assets folder

I'm going to make a java application with nifty-gui[1] using java web start
When user click on upload image, a file chooser is showed (FileOpenService)
After that, image should be visible in image control.
Unfortunately, nifty-gui can use images only from assets.
How to download this image into asset? Maybe there is a way to modify actual image using data from FileContent class?
This is solution, created after discussion [1]
assetManager.registerLoader(AWTLoader.class, "jpg");
assetManager.registerLocator("/", FileLocator.class);
image(new ImageBuilder() {{
filename("/home/marek/photo2.jpg");
}});

How to download image from .shtml using java?

I have a problem with downloading images from web-pages using java - it all works fine except for .shtml pages. Any idea? I can get the page's source but cannot download images from it. Thanks for all opinions in advance.
The shtml extension won't effect how you download the data. It just indicates that the webpage has server side included content.
There must be something else with the webpage that is tripping your up, unrelated to the extension. What this is can't be determined from the amount of information provided.

Categories