Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I cast or initialize ImageInputStream with InputStream?

I am developing an image scraping application. I am getting URL

URL imageUrl = new URL(imageSource);

Then I'm creating an InputStream with this URL:

InputStream is = new URL(imageUrl.toString()).openStream();

After this I wanna create an ImageInputStream to determine ImageIO readers.

ImageInputStream iis = ??????

But I couldn't initialize this. Can I implement URL or InputStream for ImageInputStream?

like image 436
Erçin Akçay Avatar asked Jul 23 '12 14:07

Erçin Akçay


People also ask

How do you read all bytes from InputStream?

Since Java 9, we can use the readAllBytes() method from InputStream class to read all bytes into a byte array. This method reads all bytes from an InputStream object at once and blocks until all remaining bytes have read and end of a stream is detected, or an exception is thrown.

What is ImageInputStream?

public interface ImageInputStream extends DataInput, Closeable. A seekable input stream interface for use by ImageReader s. Various input sources, such as InputStream s and File s, as well as future fast I/O sources may be "wrapped" by a suitable implementation of this interface for use by the Image I/O API.


1 Answers

this is what you are looking for :

ImageInputStream iis = ImageIO.createImageInputStream(is);
like image 147
Harmeet Singh Avatar answered Nov 15 '22 13:11

Harmeet Singh