×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    15

    desperately needs help on how to save an image in the mobile device memory

    Hi all,

    I am still struggling with saving image in the mobile device memory!
    the procedure I am following (just simply to test reading an image from the memory and writing as a new file on the memory) is as below:

    public void encode() {

    String file_name = "file://localhost/root1/photos/App1.png";
    String stegan = "file://localhost/root1/photos/App2.png";
    InputStream is;
    Image imImage, mImage;
    byte img[];
    try {
    FileConnection fc = (FileConnection) Connector.open(file_name);
    if (!fc.exists()) {
    throw new IOException("File does not exist.");
    }
    System.out.println("file size : " + fc.fileSize());
    is = fc.openInputStream();
    imImage = Image.createImage(is); //immutable image
    fc.close();
    is.close();

    //to create a mutable version of the image
    mImage = Image.createImage(imImage.getWidth(), imImage.getHeight());
    Graphics graphics = mImage.getGraphics();
    graphics.drawImage(imImage, 0, 0, Graphics.TOP | Graphics.LEFT);
    img = getByteArray(imImage);
    System.out.println("img length : " + img.length);

    FileConnection fc2 = (FileConnection) Connector.open(stegan);
    if (!fc2.exists()) {

    fc2.create();
    }

    OutputStream out;
    out = fc2.openOutputStream();
    out.write(img);
    out.close();
    fc2.close();

    } catch (Exception e) {
    e.printStackTrace();
    }

    }

    public byte[] getByteArray(Image image) {
    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];
    int n = 0;
    for (int i = 0; i < raw.length; i++) {
    int ARGB = raw[i];
    int a = (ARGB & 0xff000000) >> 24;
    int r = (ARGB & 0xff0000) >> 16;
    int g = (ARGB & 0xff00) >> 8;
    int b = ARGB & 0xff;
    rawByte[n] = (byte) b;
    rawByte[n + 1] = (byte) g;
    rawByte[n + 2] = (byte) r;
    rawByte[n + 3] = (byte) a;
    n += 4;
    }
    System.out.println("raw(int) length is: " + raw.length);
    System.out.println("raw(Byte) length is: " + rawByte.length);
    raw = null;
    return rawByte;
    }

    The job it is doing is that it creates the new file App2.png, but the size is 4 times bigger than the original image and also the format is not correct. means that the image can not be displayed.

    does anyone have any suggestions to make it work???
    I am just waiting for any ideas....
    thanks

  2. #2
    Regular Contributor
    Join Date
    Sep 2003
    Posts
    78

    Re: desperately needs help on how to save an image in the mobile device memory

    Hi,
    You can find an help at:

    http://developer.sonyericsson.com/si..._java_0502.jsp

    Bye
    Emanuele Pecorari
    My Linkedin profile: http://www.linkedin.com/in/emanuelepecorari
    My Blog: http://j2mesoccer.splinder.com
    Emanuele Pecorari
    My Linkedin profile: http://www.linkedin.com/in/emanuelepecorari
    My Blog: http://j2mesoccer.splinder.com

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. Replies: 0
    Last Post: 2007-07-15, 23:06
  3. Content Plays/Displayed; No prompt to save to device?
    By arlojj in forum Digital Rights Management & Content Downloading
    Replies: 4
    Last Post: 2006-04-21, 23:36
  4. Bluetooth Security: What exactly is an untrusted device?
    By rahulmcs in forum Bluetooth Technology
    Replies: 1
    Last Post: 2005-12-02, 06:26
  5. 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

Posting Permissions

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