×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    20

    Fill an Image with transparent data

    Hi Folks!
    I'm writting a gmae for the 6310i/3410 family phone.
    Since png cost heavier than raw data, I'm trying to create a sprite from a byte[].
    I use : DirectGraphics.drawPixels(byte[] pixels, byte[] transparencyMask,...
    It works well for a full opaque image, but I don't know how to use the "transparencyMask" !

  2. #2
    Regular Contributor
    Join Date
    Mar 2003
    Location
    UK
    Posts
    229

    RE: Fill an Image with transparent data

    You need an image for the mask, a 1 bpp PNG will do the job. Black where you want the original image opaque and white where you want transparency. Use something like this to get the byte arrays for the image and the mask:

    Image spr;
    Image msk;

    // Load in your sprite and mask Images
    // ...
    int width = spr.getWidth();
    int height = spr.getHeight();

    DirectGraphics sdg = DirectUtils.getDirectGraphics(spr.getGraphics());
    DirectGraphics mdg = DirectUtils.getDirectGraphics(msk.getGraphics());
    byte [] mask = new byte [(width * height) >> 3];
    mdg.getPixels(mask,null,0,width,0,0,width,height,DirectGraphics.TYPE_BYTE_1_GRAY);

    byte [] sprite = new byte [(width * height) >> 3];
    pdg.getPixels(sprite,null,0,width,0,0,width,height,DirectGraphics.TYPE_BYTE_1_GRAY);

    // You can discard the Image objects now if you like

    // Then draw you sprite with
    dg.drawPixels(sprite,mask,true,0,width,x,y,width,height,0,DirectGraphics.TYPE_BYTE_1_GRAY);

    Hope this helps,
    Steve

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    20

    RE: Fill an Image with transparent data

    Well, no it doesn't work :C !
    Neither on the 6310i emultor nor than 3410 real phone :C !
    Here's my code :

    byte data[] =
    {
    0, 0, -1, -1, 0, 0, -1, -1, 0, 0, -1, -1, 0, 0, -1, -1,
    0, 0, -1, -1, 0, 0, -1, -1, 0, 0, -1, -1, 0, 0, -1, -1,
    0, 0, -1, -1, 0, 0, -1, -1, 0, 0, -1, -1, 0, 0, -1, -1,
    0, 0, -1, -1, 0, 0, -1, -1, 0, 0, -1, -1, 0, 0, -1, -1,
    };
    byte mask[] =
    {
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    };
    Image sprite = Image.createImage (32, 32);
    DirectGraphics dg = DirectUtils.getDirectGraphics (sprite.getGraphics ());
    dg.drawPixels (data, mask, 0, 32, 0, 0, 32, 32, 0, DirectGraphics.TYPE_BYTE_1_GRAY);

    and then

    g.drawimage (sprite, 0, 0, Grpahics.LEFT|Graphics.TOP);

    but the resultat is not transparency ! The phone just AND the bit beetween data and mask but does not do transparency !
    :C

Posting Permissions

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