[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

SOAP::SOAPBase64 (byte array) to Image (JPG/GIF

Jalopy Jalopy

6/14/2008 7:47:00 PM

Hello,

Attempting to convert and expand on an old Java project. It pulls from
a SOAP project created from a WSDL using wsdl2ruby. The portion I am
having troubles with involves converting a "byte array" of image data
(either JPEG or GIF) into a valid image file. The soap call says it
returns an object of SOAP::SOAPBase64, but the documentation from the
server says it is a compressed image file in a byte array format.

The following is the Java code, that I want to get Ruby to duplicate:

// --------- Begin Java Code ------------------
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;

byte[] pic_bytes = getImageFromServer();
ByteArrayInputStream bais = new ByteArrayInputStream(pic_bytes);
BufferedImage bi = ImageIO.read((InputStream) bais);
ImageIO.write(bi, "JPEG", file_name);
// --------- End Java Code -------------------

I can get "data" from the server, but when I attempt to save it to a
file, it saves as characters (like ABCDEF). The Ruby version of
"getImageFromServer()" returns an object of String. I have tried
String.pack() to encode and decode from Base64, as well as other
formats, and I have tried using the RMagick library to save the image,
but the image "header" is not correct for a JPEG or GIF. I know the
Java version works, so I would like to know what about a
ByteArrayInputStream or BufferedImage makes the data become an image
that I cannot get to work in Ruby?

Thanks,
Jay
--
Posted via http://www.ruby-....