Sunday, 15 January 2012

Show Image stored in byte array form in java servlet -


I have stored as an image byte [] I Now I Java servlet I want to display I am using this code:

  response.setContentType ("image / gif"); OutputStream Out = Response. Outoutputstream (); Out.write (img); // Image byte [] is of type. Out.flush (); Out.close ();  

But I'm getting an error "The image can not be displayed because it has an error."

Actually the reason for this error was completely different. I'm executed in two phases to its function => hbase the

before byte [] and [storage and then bytes hbase] and Show through browser

The question is did I mention the address of the second half, but the real problem was the cause of the error was due to an error in Part 1:

In the beginning I thought this code < Code> Byte [] was changing the code

  file imgpath = new file ImageName;); Buffet image image buffer image = imageio Reed (IMGpath); Receive databarbackbacks from // raster writeable raster raster = buffed objects.gatorster (); DataBuffered Byte = (DataBuffered) Raster.Get DataBuffer (); Return (data .getData ());  

Which "was causing thread exception"

Error
  main "java.lang.IllegalArgumentException: Image == null javax.imageio.ImageTypeSpecifier ! but .createFromRenderedImage javax.imageio.ImageIO.getWriter (ImageIO.java:1591) (ImageTypeSpecifier.java:925) javax.imageio.ImageIO.write (ImageIO.java:1520) on com.medianet.hello.HbaseUtil.main Sun.reflect.NativeMethodAccessorImpl.invoke0 (NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) at sun.reflect.NativeMethodAccessorImpl.invoke at (HbaseUtil.java:138) Java. on Com.intelij.rt.execution.application.AppMain.main (AppMain.java:134) on) .lang.reflect.Method.invoke (Method.java:606) " 

When I code

Rw> Baitareotputstrym Baos = new Baitareonutstrym (); Buffer Image IMG = Images Reed (new file (image file)); ImageIO.write (IMG, "JPG", Baos); Baos.flush (); Return baos.toByteArray ();

It worked.


No comments:

Post a Comment