Home arrow static arrow Java Programming [Archive] - byte[] to jpg/bmp
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - byte[] to jpg/bmp
This topic has 5 replies on 1 page.

Posts:14
Registered: 8/3/01
byte[] to jpg/bmp  
Jun 28, 2004 8:01 AM



 
Hi,

I'm working with a customer to exchange some informations through a web service. He works on 4D.
I'm calling his web service that send me a byte[] variable. In fact this byte[] variable is a picture. I have to convert this variable to a jpg or bmp picture.
Can somebody tells me how to do
Thank's in advance.

(Sorry for my bad english)....
 

Posts:31,095
Registered: 4/30/99
Re: byte[] to jpg/bmp  
Jun 28, 2004 8:08 AM (reply 1 of 5)



 
What do you mean by "convert"? Do you mean you have to display it to somebody?
 

Posts:14
Registered: 8/3/01
Re: byte[] to jpg/bmp  
Jun 29, 2004 12:39 AM (reply 2 of 5)



 
Hi,
Yes, the goal is to save a jpg or bmp file. The customer send me through a web service a picture.
See what i try to do :

import com.photo.soap.axis.A_WebServicePortType;
import com.photo.soap.axis.A_WebServiceBindingStub;
import com.photo.soap.axis.A_WebServiceLocator;
import com.photo.soap.axis.A_WebService;
import org.apache.axis.AxisFault;
import java.io.*;

public class photo implements java.io.Serializable {
public static void main (String[] args){

try{
String ch="mister.t@thefactory.com";
A_WebService service = new A_WebServiceLocator();
A_WebServicePortType port = service.getA_WebServicePort();
byte[] foto = port.SOAP_Test_Notes_Photo(ch);

try{
FileOutputStream file = new FileOutputStream("D:\\tmp
foto.bmp");
ObjectOutputStream out = new ObjectOutputStream(file);
out.writeObject(foto);
out.flush();
out.close();
}
catch (java.io.IOException IOE){
System.err.println("IOException " + IOE );
}

System.out.println("photo: "+ foto);

}
catch (AxisFault af){
System.err.println(af.dumpToString());
}
catch (Exception e){
System.err.println("Exception " + e );
}

}

}

 

Posts:8,813
Registered: 10/4/00
Re: byte[] to jpg/bmp  
Jun 29, 2004 12:51 AM (reply 3 of 5)



 
Don't write to an ObjectOutputStream.
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File("foo.bmp")));bos.write(foto);bos.flush();bos.close();
 

Posts:14
Registered: 8/3/01
Re: byte[] to jpg/bmp  
Jun 30, 2004 1:07 AM (reply 4 of 5)



 
Hi,
Thank's
it's ok.
 

Posts:14,142
Registered: 99-04-02
Re: byte[] to jpg/bmp  
Jun 30, 2004 11:09 AM (reply 5 of 5)



 
that really depends on what the byte[] contains, doesn't it? Is it already a JPG or BMP file's bytes? Then write it out. If it's a raw image's bytes, you need to encode the image.
 
This topic has 5 replies on 1 page.