×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    8

    Unhappy --- ???save image problem??? ---

    I'm trying to make an Image Processing MIDlet from image that display in canvas.

    I use JBuilderX as IDE and Series60 2nd Edition Feature Pack 3 MIDP SDK as JDK.

    The making of image file in images folder is working. But, it cannot be seen and opened..

    (O ya,, when i try to save image from another image file, not image canvas, its still happened..
    i look at the file size, there's a little bit different between original and saved image..
    ex :
    oiginal file saved file
    15,7kb 22,4kb
    190kb 440kb
    the image encrypt data is different too.
    )

    Why this happenned?????
    (or, is there any header needed? or, is there any ways to save an image file?)

    Your responses will very help me..Thank u very much
    (I'm so sorry if i my question too much )


    Code:
    My Code :
    **************************************************************************
    **************************************************************************
    >>>main MIDlet program

    byte[] imgByte = null;
    Image image=null;
    .
    .
    .
    //if "save command" do this
    imageToByte();
    saveFile("file:///C:/Nokia/Images/image001.png");
    .
    .
    .
    -----------------------------------------------------------------

    >>>this procedure i adopted from mkleijer post..,

    public void imageToByte(){


    //create image from class CanvasPicture
    image = Image.createImage(CanvasPicture.instance.buffImage);

    //get width and height
    int width =image.getWidth();
    int height =image.getHeight();

    //create pixel buffer to hold the pixels of the image
    // 1 pixel = 1 int, but we can't store ints...
    int pixelData[]=new int[width*height];
    System.out.print("pilxel : p:"+width+ ", t:"+height);

    // so we create a bytebuffer which we can write to the RecordStore
    // 1 pixel = 3 bytes (or 4 when you use alpha channel)
    // we add 8 more bytes to store the width and height

    imgByte=new byte[width*height*3+8];

    //put the width and height into the first 8 bytes
    for(int b=0;b<4;b++) {
    byte widthByte=(byte)(width>>>b*8&0xff);
    imgByte[b]=widthByte;
    byte heightByte=(byte)(height>>>b*8&0xff);
    imgByte[b+4]=heightByte;
    }

    //get pixeldata from image
    image.getRGB(pixelData,0,width,0,0,width,height);

    //get red, green and blue byte from every pixel
    for(int p=0;p<pixelData.length;p++) {
    imgByte[p*3+8]=(byte)(pixelData[p]>>16); // red byte
    imgByte[p*3+8+1]=(byte)(pixelData[p]>>8); // green byte
    imgByte[p*3+8+2]=(byte)pixelData[p]; // blue byte
    }
    }

    ---------------------------------------------------------------------
    //create and write image file

    public void saveFile(String fileURL, byte[] dataByte){
    OutputStream os;

    try{
    FileConnection newImgConn = (FileConnection) Connector.open(fileURL);
    newImgConn.create();
    os = newImgConn.openOutputStream();

    for(int i=0; i<dataByte.length;i++)
    {
    os.write(dataByte[i]);
    }

    newImgConn.close();
    os.close();
    }
    catch(IOException ie){}
    }

    ********************************************************************************
    ********************************************************************************

  2. #2
    Super Contributor
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814

    Re: --- ???save image problem??? ---

    1/ you are forgetting the alpha channel
    2/ if you save an rbg byte[], it is not png, but bitmap
    3/ normally, you should be able to save directly your int[], plus with the headers, into your file

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    8

    Re: --- ???saved image problem??? ---

    Thank u for your reply njzk2!

    I have tried the factors that you were mentioned in point 1 and 2..
    but it's still same..the bitmap file was created, but cannot be opened (like before, does'nt have image attribute like format, width, height, page, etc only size).

    In the last point, i don't know how to make an header of image file (png ,jpeg, etc)..can you give an example or way to make a header to image (png)? or is there encoder image to png (in byte[]) that contained the header in one..???

    waiting for reply..

    thanks!

  4. #4
    Regular Contributor
    Join Date
    Sep 2005
    Posts
    138

    Re: --- ???save image problem??? ---

    Hello:

    I'm interesting in this thread a lot, because i need to obtain a string that represents an image. I was trying myImg.toString() or String.valueOf(myImg) but that doesn't works, and J2ME don't support serialization

    I need to encapsulate the image into XML document, and the document into a RMS store:

    <Image> dfhskdfhskdjfhskdjfhsdkfhsdkfjhsfkdfhksdjfhsdkf </Image>

    njzk2 told me a few minutes ago that i need .getRGB. I'll work around this in a few hours, and after i post here my results ok?

    If you resolve your problem, post it here, so i can look the answer.

    Bye! and good look (and sorry about my english XD)

  5. #5
    Registered User
    Join Date
    Dec 2005
    Posts
    8

    Re: --- ???save image problem??? ---

    thanks for you respons for this post pepper_91..
    such i could'nt make an "png encoder" in MIDlet..
    it's so difficult.. ;(

    anyone can help me plizz....?!?

  6. #6
    Registered User
    Join Date
    Jan 2007
    Location
    Manila, Philippines
    Posts
    39

    Unhappy Re: --- ???save image problem??? ---

    Any updates in this thread....

  7. #7
    Registered User
    Join Date
    Jan 2007
    Posts
    16

    Re: --- ???save image problem??? ---

    I also need a PNG encoder because Nokia implementation of getRGB and createRGBImage hangs on many Series 60 phones.

    It's such a shame that these primitive commands are buggy..

Similar Threads

  1. Image Upload Problem
    By tvaughton in forum Mobile Java General
    Replies: 4
    Last Post: 2005-08-17, 08:36
  2. 6600 image problem
    By ralabate in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2004-07-28, 19:42
  3. Problem of drawing FLIPPED Image after clipping in Nokia 3510i handset
    By radhesh in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2003-12-10, 03:29
  4. problem with a speed of repaint image
    By marcart in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2003-08-28, 12:10
  5. Problem with Image loading for Canvas
    By rsantossio in forum Mobile Java General
    Replies: 2
    Last Post: 2003-02-28, 00:24

Posting Permissions

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