×

Discussion Board

Results 1 to 14 of 14
  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    8

    Transparency in J2ME on Series 60

    Hi,

    I am getting really frustrated with DirectGraphics etc. Is there anywhere that I can find a simple step by step tutorial or code sample to show how transparency on a 7650 might be implemented.

    Thanks,

    Andy

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    19
    I'm not sure whether you have implemented transparency on other handsets, so I'll assume this is your first time trying.

    Firstly, the native transparent file format in MIDP is the .png file. On the Series 40 (7210, 6610, 6100), a .png file allows not only entirely transparent pixels, but also translucent ones. Unfortunately, with the Series 60 (3650, 7650) as far as I can see, only transparent pixels can be used - which is the main thing.

    Save a .png file with a transparency mask. To do this in paint shop pro:

    1. File->New Image.
    2. Draw Image.
    3. Masks->New->Show All.
    4. Masks->View Mask
    5. Masks->Edit
    6. The colour palette will change to grey scale - select absolute black (0,0,0)
    7. Paint over the pixels in your image that you wish to be invisible.
    8. Masks->Save to Alpha Channel.
    9. Hit OK twice.
    10. Save the image.

    To use the newly created image in your app (I use Sun One, so sorry if this is unspecific to your needs):

    1. Make sure you have the path with the graphics files mounted (right click on File Systems->Mount->Local Directory)
    2. Include the .png file in your jar file - In Sun One, right click the Midlet Suite Icon and select 'Edit Suite', then the tab 'Jar Contents'. Browse on the left side to the newly mounted directory, and select the png file. Click 'Add'. Click 'OK'.
    3. Create a class variable: [Image MadCrazyDudeImage=null;]
    4. In your Class constructor (or wherever appropriate), create the image from the .png file. [MadCrazyDudeImage= Image.createImage("/MadCrazyDude.png");] It is vital that the case of the name is the correct case, and that you preceed the filename with the forward slash.
    5. Create a DirectGraphics object in your paint routine, and initialise it: [DirectGraphics dg; dg=DirectUtils.getDirectGraphics(graphics);]
    6. Draw the image to the canvas. [dg.drawImage(MadCrazyDudeImage, 0, 0, Graphics.TOP | Graphics.LEFT, 0);]

    If this doesn't work, it may be that you are trying to read the graphics out of a graphics strip first (this is the part that threw me when porting my first Series 40 to a Series 60 phone). To do this, you cannot use a Graphics object alone to create your individual images. They have to be passed through a DirectGraphics object for the transparency to be maintained. I include the code that I use below:

    In the class global area:

    Image imReceptors=null;
    Image Receptors[]=new Image[12];

    imReceptors=Image.createImage("/S60receptors.png");
    for (int i=0; i<12; i++)
    {
    Receptors[i]=DirectUtils.createImage(21, 20, 0x00000000);
    Graphics g = Receptors[i].getGraphics();
    DirectGraphics dgtemp=DirectUtils.getDirectGraphics(g);
    dgtemp.drawImage(imReceptors, -21*i, 0, Graphics.TOP | Graphics.LEFT, 0);
    }
    imReceptors=null;

    It's best to put a try...catch block around your graphics creation code to make sure that there isn't a problem there (i usually just add a System.out.println("Graphics Error here") type of statemnt to the catch block). If using Sun One, you may be getting frustrated because Sun One is expecting the graphics to be located a sub folder up from where you would expect it to look for them. Try placing the images into the parent directory of your app project if Sun One is struggling to find them in the main app directory.


    I hope this helps.

    Danny.
    Tin Can Games.

    www.tincangames.com
    Last edited by danny@tincangames.com; 2003-05-28 at 08:30.

  3. #3
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    82
    Are you sure it works on series 60 ?
    Because I used the same code and it doesn't work (emu & real device 7650)

  4. #4
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    60
    as i know there is a bug or something with the transparency on s60! also in the emulator it doesnt work - dont no why and i got no solution for that.

    you cant make a transparent image with:
    MyImage = DirectUtils.createImage(16, 16, 0x00000000);
    with this code you got an image with a black background
    it only works on s40 and s30 phones



    regards
    andreas

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    19
    Hmm - not sure why you are having trouble with the above code, Fatal Error. It's taken directly from working code, running and the EPOC S60 emulator, and the actual 3650 device without any problems (its been tested by our own test team and several resellers). I can only stress again that if reading graphics out of a strip, and placing them into individual Image objects, make sure you use both a Graphics and a DirectGraphics object.

    Perhaps it is a 7650 thing (we did have reports that there was a problem with the midlet on the 7650s). Or a firmware issue.

    Sorry I can't be more helpful

  6. #6
    Registered User
    Join Date
    Jul 2003
    Location
    Finland, Tampere
    Posts
    1,113
    I constantly draw transparent images using DirectGraphics.drawPixels using format TYPE_USHORT_4444_ARGB . First four bits are responsible for transparency.

  7. #7
    Registered User
    Join Date
    Mar 2003
    Posts
    7
    Color is represented by 16 bits, so transparent color in serie 60 is:
    0x0000F000. There is F, not 0. In series 60 value of full transparent alpha is F not 0.

  8. #8
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    60
    nothing of this works
    not on the emulator and not on the phone

    if have used:

    0xF0000000
    0x0F000000
    0xFF000000
    0x0000F000 << a solid green!!!!

    any solutions

  9. #9
    Registered User
    Join Date
    Jul 2003
    Location
    Finland, Tampere
    Posts
    1,113

    Live example

    Here is copied piece of working code with transparent images.

    img.data is an array of bytes representing image. This array is in format DirectGraphics.TYPE_USHORT_4444_ARGB. Check your picture files carefully. I don't remember whether you should use 0 or F for full transparency, try both. I've got a vonvertor which converts .bmp to ARGB and successfully forgot about details

    TerrainLib.WIDTH * getOrientation() means shifting to the correct part of pixels array, I have several pictures in one array.

    Code sample:

    dg.drawPixels(img.data, true, TerrainLib.WIDTH * getOrientation(),
    img.width,
    g.getClipX(), g.getClipY(), TerrainLib.WIDTH,
    TerrainLib.HEIGHT, 0,
    DirectGraphics.TYPE_USHORT_4444_ARGB);

  10. #10
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    60
    thanks for the code!

    now i got a dark blue in the background

    i save my PNG&acute;s with photoshop
    can this be the reasen?

    my code is

    myimage = null;
    myimage = DirectUtils.createImage(16,16,DirectGraphics.TYPE_USHORT_4444_ARGB);
    g2 = myimage.getGraphics();
    g2.drawImage(loadicon,-((leveldata[li]-1)*16),0,Graphics.TOP|Graphics.LEFT);

  11. #11
    Registered User
    Join Date
    Jul 2003
    Location
    Finland, Tampere
    Posts
    1,113

    Check the format

    I have completely no idea about the PNG image format.
    I know the only thing: if you use TYPE_USHORT_4444_ARGB format you should make sure that transparency bits are set to 0 (or F, don't remember).
    If Photoshop does this, great. Otherwise you should use something else.

    Personally I don't use any PNG-files for sprites. I include to JAR prepared files containing byte arrays in the required format.

    iecomdev, it's not very complicated: output somewhere byte array which you are going to paint and check transparency bits

  12. #12
    Registered User
    Join Date
    May 2003
    Posts
    14

    got it !

    iecomdev, I just found the solution to our problems. I guess you have the same problem as me ...

    but I´ve finally found the solution ! I´m the happiest man in the world

    I was even to give up programming ... when I tried a desesperated attempt:

    use the short 0x0000 for transparent pixels and ...
    use FALSE in drawPixels !

    I mean ... dg.drawPixels(image,false,....);

    maybe it´s a mistake in the drawPixels method for the lower versions of firmware.

    Well, I´ve only tried on the emulator (0.9 beta), but I guess it also works in the phone. I´ll try.

  13. #13
    Registered User
    Join Date
    May 2003
    Posts
    14

    in adition ...

    well, the mistake in the putPixels method seems to appear only on the emulator. I´ve just tried in the phone, and we have tu put TRUE in the transparency field.

    But it works as well in the phone

  14. #14
    Registered User
    Join Date
    Mar 2003
    Posts
    7
    I didn't use drawPixel, so i haven't check if this method (0xF000) works. it works well with DirectUtils.createImage() to create transparent image on series 60. I use fillPolygon and it's drawing the same way. I don't know why drawPixels doesn't works. This is sample code:
    for(int y = 0; y<b_h; y++) {
    for(int x = 0; x<b_w; x++) {
    imgs[y][x] = DirectUtils.createImage(blockWidth, blockHeight, 0x0000F000);
    Graphics g = imgs[y][x].getGraphics();
    drawBlock(g, x+b_x, y+b_y, 0, 0, Graphics.TOP | Graphics.LEFT, cos);
    }
    }

    Method drawBlock draws a tile to the transparent image created by DirectUtils.createImage(). Created image is transparent. For n3510i requires 0x00000000 as a color value.
    Method fillPolygon() should be used the same way as createImage(). I checked it on n3650, n7650 and emulator Series60.

Posting Permissions

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