MarshalException is transferring image as byte[]

Hi
I am creating a web service which reads an image from an external url (the image is in png format).
Then I am converting the image into a bufferedimage and then sending out the image through the web service using bytearrayoutputstream.tobyteArray()
My web service client is a J2ME CLDC App . However, as soon as the stub tries to invoke the operation.
I get the exception : java.rmi.MarshalException Expected byte , received <Some very long string>. Can someone please help me out with this. It seems there is a problem in serializing the image, but am being unable to get a workaround this.
Thank you for your help
Sparsh
Here is the code am using in the web service : (The return type is a byte[])
        ImageInputStream imageInputStream = ImageIO.createImageInputStream(url.openStream() );
        ImageReader imageReader = ImageIO.getImageReaders(imageInputStream).next();
        String formatName = imageReader.getFormatName();
        imageReader.setInput(imageInputStream);
        BufferedImage sourceImage = imageReader.read(0);
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            ImageIO.write(scaledBufferedImage, formatName, byteArrayOutputStream);
            scaledBytes = byteArrayOutputStream.toByteArray();
        return scaledBytes;
    Edited by: sparshpolly on Jun 11, 2009 10:27 AM

Apparently,
J2ME does not support SOAP Attachments and the above method would create a SOAP attachment (please correct me if am wrong).
The work around this problem is
convert the bytearrayoutputstream to a base64 encoded string and then decode the string into a byte array on the J2ME client
this is the modified code :
String returnString = Base64.encode(byteOutput.toByteArray());Note the return type of the web service will now be a string. Moreover you need to include the following package for the encoding . Others are not compatible with J2ME decoding.
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
on the J2ME client
import com.sun.midp.io.Base64;
byte[] imgStream = Base64.decode(<WebServiceMethodCall>.testImage());
img = Image.createImage(imgStream, 0, imgStream.length);(Note : testImage was the name of my web service method returning the image)
Could someone, please point out why the problem actually occured with the original code ? I am not an expert in this field and would definitely like to gain an insight into this issue.
Edited by: sparshpolly on Jun 11, 2009 10:30 PM

Similar Messages

  • Transfering image in clipboard to the Oracle DB??????????

    Hi,
    Below is the code I'm using to get the image from the clipboard and display it. Basically I want to also write this image to the Oracle Database.
    Can anyone please advise me on the conversion of this image into byte and then how to transfer it to DB????
    Sample code will be a great help!!!!!!
    public static Image getClipboard() {
    Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
    try {
    if (t != null && t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
    Image text = (Image)t.getTransferData(DataFlavor.imageFlavor);
    return text;
    } catch (UnsupportedFlavorException e) {
    } catch (IOException e) {
    return null;
    void button1_actionPerformed(ActionEvent e)
    jLabel1.setIcon(new ImageIcon(this.getClipboard()));
    Many Thanks!

    But quality is a real point here.
    So you should request a slightly different feature: drag an image thumbnail from LR to Word, which in the background executes the commands
    1. Render file as somewhere specified (e.g. In a dedicated export preset for application transfer).
    2. Insert the resulting file into Word
    3. Ditch the file use for transmission.
    4. Update history of the file with this export. - maybe yiu would not be interested in this last point, but it would fit LR logic.
    The correct place to request features and let oters vote on them is another forum
    http://feedback.photoshop.com/photoshop_family/topics
    Cornelia

  • Transferring images from camera or flash drive

    Hi,
    I am having problems with transferring images. When I plug in a flash drive or my camera to the USB port,nothing pops up on my desktop. I checked System Profiler, and it appears that the computer is recognizing the flash drive. So it must be a problem with the drive talking to the software, right?
    I went into Image Capture and set the preference for iPhoto to open when a camera is attached, but no go.
    This is a new problem - I have transferred images many times since getting the computer in March.
    Help!!
    Thanks,
    Codymae

    When you make a User choice - such as 'Open iPhoto When a Camera is connected' it's recorded in the preference (or plist) file. That's what those files are. Trashing them will return the app to the default state. You can then re-select your choics. Corrupted plist files are a common cause of all sorts of issues and one of the basic troubleshooting steps for any app.
    Regards
    TD

  • Problem with getting resized image's bytes

    I've got a problem with getting correct bytes of a newly resized image. The flow is that I retrive an image from the filesystem. Due to the fact that it is large I resize it to a 50x50px thumbnail. I can display this thumbnail in #benchmark1 (see code below). Unfortunately something's wrong with my imageToBytes funtion which returns reasonably small size of image but is totally useless - I can't make an image of it anymore so at #benchmark2 the application either crashes or keeps freezing. I saved this byte array on my disk and tried to preview under Windows how does it look but I got a message "Preview unavailabe". I did some digging in the Internet and I supposed that it's because I don't use any jpg or png encoders to save the file. Actually I think that it's not the case, as the bytes returned from method imageToBytes look weird - I cannot even make a new image of them and display it without any saving in memory.
                                  byte[] bytes = FileHandler.readFile (
                                          FileHandler.PHOTOS_PATH, fileName);
                                  Image img2 = Image.createImage (bytes, 0, bytes.length);
                                  img2 = ImageHandler.getInstance ().resize (img2);
                                                    //#benchmark1
                                  bytes = ImageUtils.imageToBytes (img2);
                                  img2 = Image.createImage (bytes, 0, bytes.length);
                                                    //#benchmark2my imageToBytes function is as follows:
         public static byte[] imageToBytes (Image img)
              int[] imgRgbData = new int[img.getWidth () * img.getHeight ()];
              byte[] imageData = null;
              try
                   img.getRGB (imgRgbData, 0, img.getWidth (), 0, 0, img.getWidth (),
                           img.getHeight ());
              catch (Exception e)
              ByteArrayOutputStream baos = new ByteArrayOutputStream ();
              DataOutputStream dos = new DataOutputStream (baos);
              try
                   for (int i = 0; i < imgRgbData.length; i++)
                        dos.writeInt (imgRgbData);
                   imageData = baos.toByteArray ();
                   baos.close ();
                   dos.close ();
              catch (Exception e)
              return imageData;
    I've run totally out of any idea what's wrong, please help!
    Edited by: crawlie on Jul 17, 2010 6:21 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Hey Crawlie,
    Please note that simply writing int values into ByteArrayOutputStream will not suffice. Please have a look at the following conversion from int pixel value into byte[4]:
    public static final byte[] intToByteArray(int value) {
            return new byte[] {
                    (byte)(value >>> 24),
                    (byte)(value >>> 16),
                    (byte)(value >>> 8),
                    (byte)value
    }Good Luck!
    Daniel

  • Create image from byte[]array on server side

    Hello everyone..
    I'm developing an application which will take snapshots from a mobile device, and send it to my pc via bluetooth. I have my own midlet which uses the phone camera to take the snapshot, i want to transfer that snapshot to my pc.
    The snapshot is taken is stored in an array byte.
    The image can be created on the phone itself with no problem using : image.createImage(byte[])
    my problem is that when i send the array byte via bluetooth, and receive it on the server, i cannot create the image using the :image.createImage() code
    The connection is good since i have tested by writing the content of the array in a text file.
    Piece of midlet code:
                try{
                     stream = (StreamConnection)Connector.open(url);
                     OutputStream ggt = stream.openOutputStream();
                     ggt.write(str);
                     ggt.close();
                }catch(Exception e){
                     err1  = e.getMessage();
                }where str is my array byte containing the snapshot
    And on my server side:
    Thread th = new Thread(){
                   public void run(){
                        try{
                             while(true){
                                  byte[] b = new byte[in.read()];
                                  int x=0;
                                  System.out.println("reading");
                                  r = in.read(b,0,b.length);
                                  if (r!=0){
                                       System.out.println(r);     
                                       img = Image.createImage(b, 0, r);
                                                            //other codes
                                       i get this error message:
    Exception in thread "Thread-0" java.lang.UnsatisfiedLinkError: javax.microedition.lcdui.ImmutableImage.decodeImage([BII)V
         at javax.microedition.lcdui.ImmutableImage.decodeImage(Native Method)
         at javax.microedition.lcdui.ImmutableImage.<init>(Image.java:906)
         at javax.microedition.lcdui.Image.createImage(Image.java:367)
         at picserv2$1.run(picserv2.java:70)
    Please anyone can help me here? is this the way to create the image on the server side? thx a lot

    here is exactly how i did it :
    while(true){
                                  byte[] b = new byte[in.read()];
                                  System.out.println("reading");
                                  r = in.read(b, 0, b.length);
                                  if (r!=0){
                                       Toolkit toolkit = Toolkit.getDefaultToolkit();
                                       Image img = toolkit.createImage(b, 0, b.length);
                                       JLabel label = new JLabel(new ImageIcon(img) );
                                       BufferedImage bImage = new BufferedImage(img.getWidth(label),img.getHeight(label),BufferedImage.TYPE_INT_RGB);
                                       bImage.createGraphics().drawImage(img, 0,0,null);
                                       File xd = new File("D:/file.jpg");
                                       ImageIO.write(bImage, "jpg", xd);
                                       System.out.println("image sent");
                             }Edited by: jin_a on Mar 22, 2008 9:58 AM

  • Reading an image in byte form

    hii guys
    i m trying to read an image and convert it to byte array and later to do some change in that byte array and later recreate a new image.
    For that i m using FileInputStream and FileOutputStream and its read and write methods
    but now i dont know how to append that byte and recreate that image.
    actually i want to do that , convert the image in byte array form and replacing some bytes of the image by my text msg bytes and recreate a new image.
    how an i do that.
    plz help me.
    its urgent.

    import java.io.*;
    class image
    public static void main(String[] arg) throws IOException
    String msg;
    int len,i;
    FileInputStream fin;
    FileOutputStream fout;
    try
    try
    fin=new FileInputStream("01.jpg");
    catch( Exception e)
    System.out.println("Input image not found");
    return;
    try
    fout=new FileOutputStream("001.jpg");
    catch( Exception e)
    System.out.println("output image cannt be created");
    return;
    catch(Exception e)
    System.out.println("output image cannt be created");
    return;
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Enter the secret msg :: ");
    msg=br.readLine();
    byte[] msg1=msg.getBytes();
    len=msg1.length;
    System.out.println(len);
    for(i=0;i<len;i++)
    System.out.println(msg1);
    try
    do
    byte by=(byte)fin.read();
    //System.out.print(" "+by);
    if(fin.available()>0)
    fout.write(by);
    }while(fin.available()>0);
    catch(Exception e)
    System.out.println("File error");
    fin.close();
    fout.close();
    till now i only imputed the sg , change it into byte form .
    now i want to replace the msg bytes into the image byte as :- 1 image byte ,1 msg byte, 1 image byte , 1 msg byte........ so on
    until the msg bytes are not finished.

  • Conversion of image into byte array

    I have a problem in converting .png image into bytestream, if anyone can help in this pls do so.....

    Hi,
    To convert an Image to bytes you can use the Image.getRGB() method.
    http://java.sun.com/javame/reference/apis/jsr118/javax/microedition/lcdui/Image.html#getRGB(int[], int, int, int, int, int, int)
    -Henrik

  • Images, Thumbnails, byte[ ] and BLOB

    Hi guys,
    This is what I have to do:
    User selects image from disk and i'm putting it into DB (IBM DB2 8.0). That's clear. No problem.
    But I need that image as a thumbnail as well (I have to show images as thumbnails for each Item). I have a DB table IMAGE with 2 columns - IMAGE_FULL and IMAGE_THUMBNAIL.
    So I need to scale image(wich I have as byte array, or struts FormFile) and than put it into DB as Thumbnail.
    Or even if I don't have IMAGE_THUMBNAIL column, I have to get image as byte array from IMAGE_FULL column, scale it and show it in the browser.
    So, if I explained correctly and not very complicated way, can anyone give some ideas?
    Thanks in advance
    Gio

    For thumbnails, there's plenty of examples of resizing and saving images in the Java Programming forum, just do a search.
    For the database storage and retrieval... I had found some really good site with database examples, but I can't find it anymore.... but here's some code:
    // store
                   PreparedStatement pstmt = db.getConnection().prepareStatement(
                        "INSERT INTO TeeColor VALUES( ?, ? )" );
                   pstmt.setString(1, "yellow");
                   File fImage = new File("yellow.gif");
                   InputStream isImage = new FileInputStream(fImage);
                   pstmt.setBinaryStream(2, isImage, (int)fImage.length());
                   int res = pstmt.executeUpdate();
    // load
                   Statement stmt = db.getConnection().createStatement();
                   ResultSet rs = stmt.executeQuery(
                        "SELECT TCBlob FROM TeeColor WHERE TColor = 'Yellow'");
                   if(rs.next()) {
                        byte[] bytes = rs.getBytes("TCBlob");
                        JFrame f = new JFrame("test");
                        f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                        f.getContentPane().add(new JLabel(new ImageIcon(bytes)));
                        f.pack();
                        f.show();
                   }

  • HT201269 ibook stopped transferring images via image capture. last month it worked. i hav an old ibook and i cannot update to newest itunes. which is fine. however, i need the image capture to take photos off my iphone 5. no, i dont want to use i cloud.

    ibook stopped transferring images via image capture. last month it worked. i hav an old ibook and i cannot update to newest itunes. which is fine. however, i need the image capture to take photos off my iphone 5. no, i dont want to use i cloud. i would actually like to just plug it in to the usb drive the old fashioned way

    I don't believe the iOS7 update was the cause for your issue. I have three devices all updated and they all show the Import To drop menu in Image Capture as shown below.

  • Display image from byte array

    Hello Everybody,
    I need to display an image given in a byte array, how can I show this image in a JFrame?
    1. I tryied saving the image in a .jpg file,
         File file1 = new File("Path to my destination image");2. then I use a FileOutputStream to save the image in the path:
            FileOutputStream fos1 = new FileOutputStream(docu);
            fos1.write(ImageInbyteArray);
            fos1.close();3. Once I have the image in a file I'm trying to load it using a JButton, but the JButton doesn't display the image. I think that for some unknown (at least for me ;-) reason the file isn't still available to be used in the ImageIcon, this is my code:
            imgIconDocu = new ImageIcon("Path to my destination image");
            jBtnDocu = new JButton(imgIconDocu);What's wrong here?
    Thanks a lot

    Does the byte array contain a JPEG image? Where did
    you get the contents of the byte array?yes the array contains the JPEG image, I have a database in PostgreSQL, and the images are stored in blob in the database. I have to call a service in the server and in return it gives me the 3 images as byte arrays, that's the reason I only have the byte arrays. so I tryed saving the images as jpeg files in my hard disk to show them, but it appears that they are not available to show them in Swing after saving them. I can only show the images if I close my application and start it again :-(
    I tryed flushing and closing the FileOutputStream after the writting process (fos.write(bytearrayImage);
    fos.flush();
    fos.close();)
    Y also tryed:
    fos.write(bytearrayImage);
    fos.close();
    fos.flush();But it doesn't work either :-(
    What do you recommend me?.
    Thanks a lot,
    Johnny G L

  • Depth data convert to Image Bgr, Byte in a windows store project

    Hi,
    i use EmguCv to process depth data from Kinect v2. Now i want to do it in a windows store 8.1 app. In older project i use these code to convert from writable bitmap:
    BitmapEncoder encoder = new BmpBitmapEncoder();
    encoder.Frames.Add(BitmapFrame.Create(depthBitmap));
    MemoryStream ms = new MemoryStream();
    encoder.Save(ms);
    Bitmap b = new Bitmap(ms);
    Image<Bgr, Byte> openCVImg = new Image<Bgr, Byte>(b);
    I the project i miss the bitmap class, i search the whole day for a solution...
    Thx for any hlp
    René

    The answer with help from Canming Huang (Thx):
    private Image<Bgr, Byte> Array2IImage(byte[] pixelArray)
    GCHandle dataHandle = GCHandle.Alloc(pixelArray, GCHandleType.Pinned);
    try
    using (Image<Bgra, Byte> image = new Image<Bgra, byte>(this.pixelWidth, this.pixelHeight, this.pixelWidth * this.cbytesPerPixel, dataHandle.AddrOfPinnedObject()))
    return image.Convert<Bgr, Byte>();
    finally
    dataHandle.Free();

  • Problem with tethering D700 - slows down: 'Transfering images...'

    Hi,
    I have a problem when working tethered. Previously I had no or hardly any trouble but as far as I know nothing has changed.
    The problem is (also when I have no CF card in my camera) that all of a sudden I get 'transferring images from camera' and lightroom then is fully occupied doing that. It is a big problem because I cannot work lik that in the studio.
    Please advice bcause it is driving me mad...
    Leon

    Hi Weixuan,
    I recomend taking an unneccesarily process out if the loop for example: IMAQ Create, IMAQ Read File, IMAQ WindSetup, IMAQ Dispose, IMAQ WIndClose.
    You may refer to my attached screenshot to see how I modify your program.
    I can achieve the same task at 17ms interval with <30% CPU consumption.
    Regards, Kate
    Attachments:
    weixuan.PNG ‏16 KB

  • Image to byte array

    hello,
    how can i get an image in jar file as a byte[] or can i convert an image to byte[]?
    thx...

    To read a bytes from a jar file, use a JarInputStream. If you're just trying to read bytes from a jar, it doesn't make any difference whether it's an image or not.
    To get the bytes from an Image, you need to put more information in your question - are you talking about an image file, like a JPEG or TIFF? What do you want to do with it? Or are you talking about an Image object in Java? If so, which specific concrete subclass, and what do you want to do with it?

  • Image to byte[]

    What is the best way to convert an object of type Image to byte[]. I would prefer not to write to disk.
    Thanks,
    Eric

    what do you want in the byte[]?
    The pixel data, or the object itself?
    Pixel data, use PixelGrabber,
    Object itself, use ObjectOutputStream, with an underlying ByteArrayOutputStream.

  • Transfering Image Files

    Ok, so I have a question.
    Can I have, say, 10 Image variables in my applet. And then get images to these variables through an input stream? THen, when I'm done using these images and want 10 new images, I can use the input stream again to write over the current image values with the new image values?

    You should be very careful with questions like "can I .." and "is it possible to .." because people will feel tempted to reply with "yes" or "no" which is probably not what you want. Instead you should be asking "how would I .."
    The answer to your question is yes, the details of "how" depend on which image format you use and whether you want to avoid certain software library dependencies. If you don't want to depend on the new ImageIO library you can use services of the java.awt.Toolkit class: the createImage(byte[] imagedata, int imageoffset, int imagelength) can create an image from bytes in JPEG, GIF, and PNG format, and the createImage(ImageProducer producer) can create an image from any ImageProducer (= you can use a custom image format but have to write the ImageProducer implementation to decode the stream yourself).
    API: http://java.sun.com/j2se/1.4.1/docs/api/java/awt/Toolkit.html

Maybe you are looking for