×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Regular Contributor
    Join Date
    Aug 2003
    Posts
    68

    drawPixels and getPixels - use int[], byte[] or short[] ??

    I have created a canvas object which is using loads of memory, resulting in an "Unable to run application" alert displaying, or the emulator (7210) just freezing.

    So I'm going thru my code to try and improve things.

    Firstly, I am creating some images with DirectGraphics's getPixels and drawPixels method. I am currently using these with short arrays (as advised), but wouldn't it be better to use int arrays?

    Also, I am loading a few small PNG's. These could possibly be created in the application instead, but would doing this be a good or bad thing in terms of memory usage?

    Any other suggestions most appreciated.

    Cheers,
    James

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    Firstly, I am creating some images with DirectGraphics's getPixels and drawPixels method. I am currently using these with short arrays (as advised), but wouldn't it be better to use int arrays?
    What kind of array depends on the supported color format(s) on the phone. But if you're running out of memory why do you think an int (4 bytes) is better that a short (2 bytes)?
    Also, I am loading a few small PNG's. These could possibly be created in the application instead, but would doing this be a good or bad thing in terms of memory usage?
    If the resulting images are the same size they will take up the same amount of memory at runtime.

    shmoove

  3. #3
    Regular Contributor
    Join Date
    Aug 2003
    Posts
    68
    Shmoove,

    (Sorry, I meant to say wouldn't it be better to use *byte* arrays rather than short arrays.)

    Am I right in assuming that most/all colour phones would support TYPE_BYTE_332_RGB - in which case I could use byte arrays ??

    NB - I've drastically improved the memory probs by calling System.gc() at the beginning and end of the paint() method.

    Thanks,
    James

  4. #4
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    I don't know about that. You probably can't count on it. The only way I know to find if the phone supports the format is by trying to use drawPixels() and catching an IllegalArgumentException (anyone know any documents with this information??). But one thing is for sure: if you don't use the phones native pixel format your performance will drop since the function will have to convert the array to the native format before it can draw it.
    Here's a quote from the Nokia javadocs:
    public int getNativePixelFormat()
    Returns the native pixel format of an implementation. The method returns the pixel format, for example, TYPE_BYTE_1_GRAY or TYPE_USHORT_4444_ARGB. The native format is the most efficient format supported by the drawPixels and getPixels methods of specific implementation. An implementation must support the format that it returns from this method. Implementation may support also other pixel formats.
    Notice that it says: "may support also other pixels formats". There are no guaranties.

    shmoove

  5. #5
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    And as far as I know the native pixel format on most phones is TYPE_USHORT_4444_ARGB (all the 4096 color models).

    shmoove

  6. #6
    Regular Contributor
    Join Date
    Aug 2003
    Posts
    68
    according to getNativePixelFormat(), for the 7210 emulator it's TYPE_USHORT_444_RGB (444).

Posting Permissions

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