Updated Image not getting reflected - java

I am trying to crop image.There is an ajax call made to the server end where cropping takes place and original file gets replaced with cropped image.
Now when i get back the control, i still see the old image even though cropped image exists at the same location.
Changes reflect only after page refresh which i don't want users to do it.Code for crop image is as follows
BufferedImage originalImgage = ImageIO.read(new File(filePath+"\\"+subFolder+"\\"+fileName));
ImageIO.write(originalImgage,extention,new File(filePath+"\\"+subFolder+"\\"+dateStamp+"_"+fileName));//save original image
BufferedImage SubImgage = originalImgage.getSubimage(xAxis,yAxis,width,height);
File outputfile = new File(filePath+"\\"+subFolder+"\\"+fileName);
ImageIO.write(SubImgage,extention,outputfile);
pls help
Thanks

Try to replace the image src parameter with the new path returned from ajax in ajax success call back.

Well after struggling a lot finally found the problem.The image is cached by the browser. So whenever u do any operations on image on the same file location , the latest copy is not download.Instead old image from cache is still referred.
Hence the solution was to make browser download latest copy.This was simple.
Append dummy parameter to file path forcing browser to download
rand = new Date().getTime();
var image_Path = filePath+"?crop="+rand

Related

Changed Image file is not getting displayed using struts2

I am tring to upload a file using struts2.File uploading is successful.I tried out many hints from stack overflow,but still failed to find a solution for this.
Nw when i try to change the image,the new image appears only after clearing the cache.It does not change spontaneously.The struts2 framwork makes use of tiles and
the images are getting displayed on header and leftContainer.
The file is named after the memberId logged in..(which is stored in session)
I made use of fileUpload code from:
http://www.tutorialspoint.com/struts_2/struts_file_uploads.htm
destPath = org.apache.struts2.ServletActionContext.getServletContext().getRealPath("/");
destPath = destPath + "images";
//where images are stored in images folder of webapps..
When i try uploading a new image,this image will be renamed by the memberId of the loggedin member(stored in session).
What my exact problem is that, new file is getting successfully uploaded to the images path.It is also renamed correctly.But this new image appears only when i either refresh the page or clear the cache.Why is this so??
How can refreshing be avoided?
Please help..........

Caching Zoomable Web Image

Aquery
Zoomable Web Image
In addition to ImageView, a WebView can be used to display an image along with Android build in zoom support for WebView. Image will be centered and fill the width or height of the webview depending on it's orientation.
I using,
String url1 = "file:///mnt/sdcard/image.jpg";
aq.id(R.id.webView1).progress(R.id.progress).webImage(url1);
I noticed that even if I cut off the connection and re-open that application, the image is still displayed. Is it cached? I looked into its sd card folder, nothing there. I'd like to utilize cached images instead of fetching it many times.
Also, I am both using Universal-Image-Loader and Android Query. I am just concern if they can both read cached images.
//Aquery
//returns the cached file by url, returns null if url is not cached
File file = aq.getCachedFile(url);
The url1 is being downloaded every time you call
aq.id(R.id.webView1).progress(R.id.progress).webImage(url1);
Your cached file is being returned to File file object but you arent making use of it in

How to load an image in Java using toolkit and new URL

I need to use a JPEG image in my Java applet.
In my applet class, I define the image name and create an object to ImageBuffer class.
String iname= "image1.jpg";
b = new ImageBuffer(iname,this);
In the ImageBuffer class, I call
Image image = null;
image = Toolkit.getDefaultToolkit().getImage(new URL(applet.getCodeBase(),fileName));
While this does not flag an error and image is not null anymore, it does not initialize image correctly. The height and width are -1. The url of the path however appears to be correct : /C:/Users/..../image1.jpg
How do I correctly load the image? It is in the bin file of my Eclipse project currently.
The height and width are -1.
Use a MediaTracker to monitor the asynchronous loading progress of the image. Alternately use ImageIO to load the image prior to the next code line.
If the image is placed in the correct location, then this would fix it
image = new ImageIcon(Toolkit.getDefaultToolkit().getImage(new URL(applet.getCodeBase(),fileName))).getImage();
If the code returns a NullPointerException it means the image is not placed in the correct directory.

GWT Image setUrl()

i am using - and new to - GWT and i made an Image Widget to view an image. This image is found on my file system i wrote.
String src = "file:///D:/myfolder/myfile.jpg";
Image image = new Image();
image.setUrl(src);
but image doesn't appear!
You should specify either the whole URL (http://www.example.com/img/myfile.jpg) or (better yet) just relative to the root: /img/myfile.jpg. And, of course, you have to place your images in your WAR directory.
That's the simple setup. If you have more images and want to optimize fetching them (many images -> many requests to the server), have a look at the ClientBundle.

Retrieve an image from the web in java

I am trying to read an image that resides somewhere on the web from my Java program. So far I have successfully loaded an image by using the following code.
URL url = new URL("http://www.google.com/images/nav_logo4.png");
Image img = Toolkit.getDefaultToolkit().getImage(url);
What I want to know is why this code (which is the first i tried) does not work:
BufferedImage img = ImageIO.read(new File("http://www.google.com/images/nav_logo4.png"));
This would have the benefit of giving me a BufferedImage. Also, how can I make the above code block until the image is loaded? I know I can use an ImageObserver, but is there a simpler way?
When I try the second option, I get this exception:
javax.imageio.IIOException: Can't read input file!
A File cannot refer to a URL.
Although I haven't tried it, there appears to be a ImageIO.read(URL) method, which can take an URL as the input as an URL object.
I would presume it would be called as follows:
ImageIO.read(new URL("http://url/to/my/image.png"));
File objects cant read from URLs

Categories

Resources