Meaningless Drivel is fun!*
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 Spring in Action this week in the Spring 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: 42277
    
  64
Is "bin" null?


Ping & DNS - my free Android networking tools app
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: 42277
    
  64
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: 4181
    
  21

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: 42277
    
  64
I'll ask again:
Ulf Dittmer wrote:Is "bin" null?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: imageio.read Bytearrayinputstream null