Hi All,

Thank you so much for the many replies.
Tried out the solution and library suggested by Xi just now, since his
solution was the easiest to verify.
It works.

After having downloaded this library:
http://sourceforge.net/projects/migbase64/

I convert the byte string like this:
String base64String = "data:image/png;base64," +
Base64.encodeToString(image,false);

Then simply use it at the client side like this:
Image image = new Image(base64String);

The image now displays. I think the base64 library I initially used
was not browser safe as Jens and Thad suggested.
Would have build a servlet as Jens suggested if it had not worked.

As for your question Alexandre, I don't know why the service developer
suggested I could not use base64.
Could have been inexperience on his behalf :-). Clearly base64 does
work.

On Sep 17, 12:02 am, Xi <chenx...@gmail.com> wrote:
> Hi,
>
>     I've usedhttp://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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to