×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    28

    Post Save image in record store

    hello guys is there anyway to store an image in the recordstore... i wrote a program to take pictures using phone camera... i want to store it in memory so that i can retrieve it in future.. but as record store allows only data in byte format i want to know how i can convert image to bytes so that i can store it in recordstore...

  2. #2
    Registered User
    Join Date
    Sep 2007
    Location
    Mumbai, India
    Posts
    54

    Re: Save image in record store

    There u go--->

    public boolean cacheImages(String ImageName,Image img)
    {
    int width = img.getWidth();
    int height = img.getHeight();
    byte[] outputRecord;
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    DataOutputStream outputDataStream =new DataOutputStream(outputStream);
    int[] imgRgbData = new int[img.getWidth() * img.getHeight()];

    try {

    img.getRGB(imgRgbData, 0, width, 0, 0, width, height);

    } catch (Exception e) {
    // Problem getting image RGB data
    }
    try {
    // Write image data to output stream (in order to get
    // the record bytes in needed form)
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(baos);
    dos.writeUTF(ImageName);

    for (int i = 0; i < imgRgbData.length; i++) {
    dos.writeInt(imgRgbData[i]);
    }

    // Open record store, create if it doesn't exist
    rms.addRecord(baos.toByteArray(), 0,baos.toByteArray().length); // Add record


    } catch (RecordStoreException rse) {
    // Other record storage problem
    return false;
    } catch (IOException ioe) {
    // Problem writing data
    return false;
    }

    return true;
    }


    Write the image in a byte array format. Also store the image name, and the form factor(width, height) as they will be usefull while reading the images from the rms.

    Hope this helps

  3. #3
    Super Contributor
    Join Date
    Feb 2006
    Posts
    689

    Re: Save image in record store

    Hii Nimesh,
    it is not wise to store images in record store because of the size limit.Just store these images in the phones and just store the URL of these images in the record store...I think this is very better when compared to the other one.
    Thanks
    Soku

Similar Threads

  1. store image in recordstore
    By cars2004 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 9
    Last Post: 2008-12-13, 05:20
  2. Display, modify and save image
    By mazi888 in forum Symbian Media (Closed)
    Replies: 1
    Last Post: 2006-03-13, 20:14
  3. Record Store vs JDBC. How to store data?
    By 180ºrevolution in forum Mobile Java General
    Replies: 0
    Last Post: 2004-09-17, 15:24
  4. 3650 & Record Store
    By basarim in forum Mobile Java General
    Replies: 4
    Last Post: 2003-12-10, 22:20

Posting Permissions

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