×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Nokia Developer Champion
    Join Date
    Apr 2007
    Posts
    2,708

    Transparant Rectangle, possible ?

    Hi all,
    I wanted to paint a filled rectangle with transparency on my Canvas ?
    Specifically like a semi-transparent rectangle, so not completely transparent...
    Any idea's on how to succeed ? I've been searching on the net but I haven't found any real answers regarding this. Afaik it's not possible directly through the Graphics class, simply because using the g.setColor() method only the RGB values are passed and no aplha...

    Any tricks maybe ? like using a 1 by 1 pixel Image and keep copying this till u have a rectangle ?

    Im anxious to hear any input regarding this issue,
    thx in advance
    Last edited by Tiger79; 2008-08-22 at 11:48.

  2. #2
    Registered User
    Join Date
    Jul 2008
    Posts
    7

    Re: Transparant Rectangle, possible ?

    Hi this work only in MIDP 2

    public static final void drawAlphaRect(Graphics g, byte alpha, int color, int borderColor, int x, int y, int w, int h)
    {
    int size = w * h;
    int[] alphaRGB = new int[size];
    for( int i = 0; i < size; ++i )
    alphaRGB[i] = color|(alpha<<24);

    Image alphaBack = Image.createRGBImage(alphaRGB, w, h, true);
    g.drawImage(alphaBack, x, y, 0);

    g.setColor(borderColor);
    g.drawRect(x, y, w, h);
    }

  3. #3
    Nokia Developer Champion
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Transparant Rectangle, possible ?

    thx,
    just one question about the supplied arguments to the method :

    Graphics g == the graphics object
    byte alpha == please could you explain this one to me ? values and effects ?
    int color == I guess this is the (partly) transparant color
    int borderColor == the color of the border of the rectangle ?
    int x == starting x coordinate
    int y == starting y coordinate
    int w == width
    int h == height

    Could u please explain the alpha (maybe show an example for a 80% transparant alpha value) and the color variable (guess like white would be 0xFFFFFF?) ?

  4. #4
    Nokia Developer Champion
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Transparant Rectangle, possible ?

    thx for the help !
    In the end I managed by creating a byte alpha mask in the following way

    byte neededAlpha = (byte)200; //200 out of 255

    and for the passed color as in my previous post (0xffffff for white for example).

  5. #5
    Registered User
    Join Date
    Jul 2008
    Posts
    7

    Re: Transparant Rectangle, possible ?

    byte alpha: you should use 0x00 to 0xFF to get the diferents values of alpha transparency

Similar Threads

  1. drawing a rectangle
    By Jeepy in forum Symbian
    Replies: 5
    Last Post: 2009-01-19, 10:39
  2. Help me to draw line and rectangle
    By RB_Sahu in forum Symbian User Interface
    Replies: 6
    Last Post: 2008-03-10, 10:40
  3. Drawing rectangle
    By usuf in forum Symbian Media (Closed)
    Replies: 6
    Last Post: 2008-01-18, 06:31
  4. Efficiency: drawing rectangle or using label
    By xhsoldier in forum Symbian
    Replies: 6
    Last Post: 2008-01-07, 06:24
  5. How to set emulater property so that it will display transparent images transparant
    By vinay3dec in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2004-09-08, 09:41

Posting Permissions

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