aspose file tools*
The moose likes General Computing and the fly likes imageio.read Bytearrayinputstream null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » General Computing
Bookmark "imageio.read Bytearrayinputstream null" Watch "imageio.read Bytearrayinputstream null" New topic
Author

imageio.read Bytearrayinputstream null

ramesh poorella
Ranch Hand

Joined: Jul 19, 2011
Posts: 60
Hi ,
The bellow is my code, here i got the null at bimg = ImageIO.read(bin);


java.io.InputStream in = new FileInputStream("D:\\123.tif");
int size=in.available();
byte[] buff = new byte[8000];

int bytesRead = 0;
ByteArrayOutputStream bao = new ByteArrayOutputStream();
buff = new byte[in.available()];
while((bytesRead = in.read(buff)) != -1) {
bao.write(buff, 0, bytesRead);
}

byte[] data = bao.toByteArray();


BufferedImage bimg;
java.io.InputStream bin = new ByteArrayInputStream(data);
try {
bimg= ImageIO.read(bin);
} catch (IOException ioe) {
throw new RuntimeException(
"Failed to render image",
ioe);
}




please help me why i am getting null value
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
Is "bin" null?


Ping & DNS - updated with new look and Ping home screen widget
ramesh poorella
Ranch Hand

Joined: Jul 19, 2011
Posts: 60


bin is not getting null.

bimg is getting null
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
Not sure what "getting null" means - *is* it null?
ramesh poorella
Ranch Hand

Joined: Jul 19, 2011
Posts: 60

bimg is null
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 3971
    
  17

According to the api for javax.imageio.ImageIO the read() method would return null if there is no registered reader that can decode the image file. So you need to find a reader which will read that type of file and make sure it gets loaded.


Steve
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
I'll ask again:
Ulf Dittmer wrote:Is "bin" null?
 
 
subject: imageio.read Bytearrayinputstream null
 
Similar Threads
streaming an HTML document
facing problem in writing Excel Doc bytes into ServletOutputStream
Upload and Resize Advice
how to convert a Bytearray input stream to String
Convert image to byte[] and viceversa