Re: byte array to Image
Hi,
I've used http://sourceforge.net/projects/migbase64/ in my
application, to convert the byte array to a base64 string, which works
pretty well and efficient
My code is like : String base64 = "data:image/png;base64," +
Base64.encodeToString(bytes,false);
And at the client side, you just set the value into an image
element's "src" attribute.
But be careful, IE CAN NOT take charge of an image that bigger
than 32KB by using the "Base64" way.
Hope this can help you.
On 16 sep, 12:54, AgitoM <karel.m...@gmail.com> wrote:
> Hi all,
>
> From a web service I am receiving a byte array that represents a
> image.
> I need to somehow squeeze this byte array into a image widget or
> similar widget on my client side.
>
> First I tried to convert the byte array to a base64 string:
> String base64 = Base64Utils.toBase64(image);
> base64 = "data:image/png;base64,"+base64;
>
> This didn't work. The developer of the web service informed me that I
> should not convert the byte array to a base64 string, and just use it
> directly.
>
> To test if the byte array represented a correct image, I saved the
> byte array to a physical image:
> InputStream in = new ByteArrayInputStream(image);
> BufferedImage bImage = ImageIO.read(in);
>
> File outputfile = new File("saved.png");
> ImageIO.write(bImage, "png", outputfile);
>
> This succesfully resulted in a physical image being created.
>
> However I don't want to write the file and then send the URL to the
> image widget on my client side.
>
> Anybody have any suggestion about how I can get this byte array
> squeezed into a image?
> Or convert this byte array to a base64 string that does work?
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home