I am trying to read the following image
But it is showing IIOException.
Here is the code:
Image image = null;
URL url = new URL("http://bks6.books.google.ca/books?id=5VTBuvfZDyoC&printsec=frontcover&img=1& zoom=5&edge=curl&source=gbs_api");
image = ImageIO.read(url);
jXImageView1.setImage(image);
You are getting an
HTTP 400
(Bad Request) error because there is aspace
in your URL. If you fix it (before thezoom
parameter), you will get anHTTP 400
error (Unauthorized). Maybe you need some HTTP header to identify your download as a recognised browser (use the "User-Agent" header) or additional authentication parameter.For the User-Agent example, then use the ImageIO.read(InputStream) using the connection inputstream:
Use whatever needed for
xxxxxx
Directly calling a URL to get an image may concern with major security issues. You need to ensure that you have sufficient rights to access that resource. However You can use
ByteOutputStream
to read image file. This is an example (Its just an example, you need to do necessary changes as per your requirement.)This code worked fine for me.
You can try the this class to displays an image read from a URL within a JFrame.
Ref : https://gist.github.com/aslamanver/92af3ac67406cfd116b7e4e177156926
Try This:
Try This:
}