Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

imageio.read Bytearrayinputstream null

 
ramesh poorella
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is "bin" null?
 
ramesh poorella
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


bin is not getting null.

bimg is getting null
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what "getting null" means - *is* it null?
 
ramesh poorella
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

bimg is null
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll ask again:
Ulf Dittmer wrote:Is "bin" null?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic