locked
Drawing an image over other with backgroung transparency RRS feed

  • Question

  • Hello!

    I want to draw an image over other without drawing its backgroud. The image that I want to draw it's a star. I want to put some stars over a map image.

    The problem is that the star's image has a white backgroud and when I draw over the map the white background appears.

    My method to draw the star is like this:

    Graphics

    graphics = Graphics.FromImage(map);
    Image customIcon = Image.FromFile("../../star.png");
    graphics.DrawImage(customIcon, x, y);


    I tried with transparent backgroud images (PNG and GIF formats), and it always draw something surrounding the star. How can I draw a star without its background?

    The program is for Windows Mobile 5.0 and above, with Compact Framework 2.0 SP2 and C#.

    Thank you!
    • Edited by VansFannel Sunday, July 26, 2009 3:00 PM correct format
    Sunday, July 26, 2009 2:58 PM

Answers

All replies

  • Sunday, July 26, 2009 4:06 PM
  • Hi,

    Thanks for your answer but I want to draw an icon over a map without drawing icon's background. The post talk about controls with transparent background.

    Thank you for your answer.
    Sunday, July 26, 2009 7:11 PM
  • Hello,

    Can you please refer the link below-

    http://social.msdn.microsoft.com/Forums/en-US/vssmartdevicesvbcs/thread/43fd47d3-6d72-4833-85bf-ad1088ee123f

    Please let me know if you still have any problem.

    Regards,
    Amit Rote
    • Proposed as answer by Amit Rote Monday, July 27, 2009 11:57 AM
    • Marked as answer by VansFannel Monday, July 27, 2009 12:55 PM
    Monday, July 27, 2009 4:47 AM
  • Hello,

    Following the code on http://social.msdn.microsoft.com/Forums/en-US/vssmartdevicesvbcs/thread/43fd47d3-6d72-4833-85bf-ad1088ee123f I wrote:


    Graphics g = Graphics.FromImage(mapa);
    Image iconoPOI = (System.Drawing.Image)Recursos.imagenPOI;
    Point iconoOffset = new Point(iconoPOI.Width, iconoPOI.Height);

    System.Drawing.Rectangle rectangulo;
    ImageAttributes transparencia = new ImageAttributes();
    transparencia.SetColorKey(Color.White, Color.White);

    rectangulo = new System.Drawing.Rectangle(x, y, iconoPOI.Width, iconoPOI.Height);
    g.DrawImage(iconoPOI, rectangulo, x, y, iconoPOI.Width, iconoPOI.Height, GraphicsUnit.Pixel, transparencia);


    But I don't see anything on map.

    X and Y are de coordinates where I want to draw the iconoPOI which it's a PNG imagen with a white background.

    What I'm doing wrong?

    Thank you!

    Monday, July 27, 2009 10:54 AM
  • i would suggest you to please retest the same by replacing White color with different color in the image as well as in the code.
    please try the same and let me know if you still have the problem.

    Regards,
    amit Rote
    • Edited by Amit Rote Monday, July 27, 2009 11:00 AM added
    • Proposed as answer by Amit Rote Monday, July 27, 2009 11:56 AM
    Monday, July 27, 2009 10:59 AM
  • I've changed and I don't see anything.
    Monday, July 27, 2009 11:15 AM
  • I guess the problem is in the statement-
    g.DrawImage(iconoPOI, rectangulo, x, y, iconoPOI.Width, iconoPOI.Height, GraphicsUnit.Pixel, transparencia);
    the parameter x,y should be replaced with 0,0. Because those are related to the Source rectangle.

    regards,
    amit rote
    • Proposed as answer by Amit Rote Monday, July 27, 2009 11:56 AM
    • Marked as answer by VansFannel Monday, July 27, 2009 12:03 PM
    Monday, July 27, 2009 11:56 AM
  • Yeah, you did it!

    Thank you very much!

    Monday, July 27, 2009 12:03 PM