×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    13

    Image Format(urgent)

    Hi
    We are developing Client/server application. Server is Mobile Agent and client is desktop PC. We are sending images from device to PC. These images are application canvas screens. We are grabbing images by using NokiaUI api. We are capturing the present screen by using bellow statements:
    Int rgbi[];
    …..
    …..
    dg.getPixels(rgbi, 0, w, 0, 0, w, h,DirectGraphics.TYPE_INT_888_RGB);


    after getting the image array I am converting in to byte array by using below algorithm and I am sending this byte array to PC.


    int[]raw = new int[image.getWidth() * image.getHeight()];
    image.getRGB(raw, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight());

    byte[]rawByte = new byte[image.getWidth() * image.getHeight() * 4];// ARGB
    int a, r, g, b;
    int n = 0;

    for(int i=0; i<raw.length; i++){

    // Right-shift the values to fit in a byte.
    int ARGB = raw[i];
    a = (ARGB & 0xFF000000) >> 24;
    r = (ARGB & 0xFF0000) >> 16;
    g = (ARGB & 0xFF00) >> 8;
    b = (ARGB & 0xFF);

    rawByte[n] = (byte)b;
    rawByte[n+1] = (byte)g;
    rawByte[n+2] = (byte)r;
    rawByte[n+3] = (byte)a;
    n+=4;
    }



    My problem is, this byte is received successfully but whenever we try to display this image it giving error. Before displaying image we are converting this byte array into int array and displaying. In Pc we are using C++.

    Can you please tell me what is array format (i.e. PNG or RAW data)?
    If it is a raw data what is the way to convert this raw data into BMP format?

    Are you having any other idea to display canvas image in PC?

  2. #2
    Regular Contributor
    Join Date
    Aug 2006
    Posts
    307

    Re: Image Format(urgent)

    Working with bytes in Java might be surprizing, especially when you're working with unsigned bytes, which for example are in ARGB data. The best way to avoid troubles with byte conversions is to use the standard byte array streams. Especially, wrapped into the DataInput or DataOutput streams. Here the code, which will do the same job, but without heavy convertions:

    Code:
    // this will keep the data you're going to send to the server
    
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    
    
    // this component has some really good methods to put the data inside
    
    DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
    
    
    // now let's put data inside the DataOutputStream
    
    int rawLength = raw.length;
    
    for (int i = 0; i < rawLength; i++) {
        
        dataOutputStream.writeInt(raw[i]); // simply store current pixel
    
    } // end for each pixel
    
    
    // now extract stored pixels as byte array
    
    byte[] rawByteData = byteArrayOutputStream.toByteArray();
    
    
    // and I guess you'll be able to send it to the server now
    Hope this will help you. And just a tip: try to avoid using the array.length in for or while loops, especially if you'll have a lot of iterations. By default the Java will ask for the length each time the loop is iterating, so taking in mind how much pixels you may process, it simply would take more time and accumulator power than if you would use some integer variable instead of the raw.length.
    Last edited by axs; 2007-05-24 at 12:06.

Similar Threads

  1. --- ???save image problem??? ---
    By ferenn in forum Mobile Java Media (Graphics & Sounds)
    Replies: 6
    Last Post: 2007-10-01, 14:33
  2. Opening a JPEG Image
    By ummarbhutta in forum Mobile Java Media (Graphics & Sounds)
    Replies: 8
    Last Post: 2007-02-15, 06:34
  3. how to cut some part of Image
    By mshouab in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2006-08-04, 09:05
  4. HELP: Mutable Image to Immutable Image?
    By rj_cybersilver in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2005-03-26, 09:58
  5. Nokia Image Converter
    By davidpurdie in forum General Development Questions
    Replies: 0
    Last Post: 2004-02-18, 15:31

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×