×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    31

    drawpixels in Nokia API

    Hi,
    I first found out the pixels of an image and save it in the rms. Thn i take those pixels and copy it in an array. But whn i draw using those pixels the image does not come properly. there's lot of space between thm. can nyone help to get proper image using only pixels and not using image.

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    Show us the code to save and load the pixel arrays to/from the RMS. I'm guessing something is wrong there.

    shmoove

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    31
    I get the pixels using getPixels of Nokia API.
    The following is the class I use to save the pixels in a the form of a single string in the rms.

    class SaveGame
    {
    static RecordStore myGame;
    static boolean gameHaveBeenInit =false ;
    static String gameData;

    private SaveGame()
    {
    }

    private static void initialize()
    {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(baos);
    byte[] b;

    try
    {
    try
    {
    dos.writeUTF("A");
    b = baos.toByteArray();
    dos.close();
    }
    catch (IOException ioe)
    {
    System.out.println(ioe);
    throw new RecordStoreException();
    }

    myGame.addRecord(b, 0, b.length);
    }
    catch (RecordStoreException rse)
    {
    close();
    System.out.println(rse);
    }
    }
    static void open()
    {
    try
    {
    myGame = RecordStore.openRecordStore("ABC", true);

    if (gameHaveBeenInit) return;

    if (myGame.getNumRecords() == 0)
    {
    initialize();
    }
    else /* Read myGame */
    {
    ByteArrayInputStream bais;
    DataInputStream dis;
    byte data[];

    data = myGame.getRecord(1);

    if (data != null)
    {
    try
    {
    bais = new ByteArrayInputStream(data);
    dis = new DataInputStream(bais);

    gameData = dis.readUTF();
    dis.close();
    if (gameData.equals(""))
    {
    gameData = "A";
    saveGame(gameData);
    }
    }
    catch (IOException ioe){}
    }
    }
    gameHaveBeenInit = true;

    }
    catch (RecordStoreException rse){System.out.println(rse); }
    }

    static void close()
    {
    if (myGame != null)
    {
    try
    {
    myGame.closeRecordStore();
    }
    catch (RecordStoreException frse) { }
    myGame = null;
    }
    }

    static void saveGame(String gamedata)
    {
    ByteArrayOutputStream baos;
    DataOutputStream das;
    byte[] data;
    try
    {
    try
    {
    baos = new ByteArrayOutputStream();
    das = new DataOutputStream(baos);

    das.writeUTF(gamedata);
    data = baos.toByteArray();
    das.close();
    }
    catch (IOException ioe)
    {
    throw new RecordStoreException();
    }

    if (myGame == null)
    {
    open();
    myGame.setRecord(1, data, 0, data.length);
    close();
    }
    else
    {
    myGame.setRecord(1, data, 0, data.length);
    }
    }
    catch (RecordStoreException rse){}

    gameData = gamedata;
    }


    static String getGameData()
    {
    if (!gameHaveBeenInit)
    {
    open();
    close();
    }
    return gameData;
    }
    }

Posting Permissions

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