How do I draw an image with a transparent section to a Graphics object in C#?
I have a Graphics object that I am drawing to and displaying. This is working fine. The thing that is not working is drawing a .png image with a transparent section. I am drawing these images from am ImageList control (if that makes any difference) with the call:
myGraphicsObject.DrawImage(myImage, x_position, y_positio开发者_开发百科n);
I have not specifically set any transparent color value for the .png image and I cannot find any value in my control that specifies a transparent color for the control.
For the image itself I have tried filling the transparent colors for 32bit (255,0,255), 8bit (0,0,0), and white (255,255,255) in the desired transparent sections. None are not transparent when drawn, though.
Is there a method somewhere that tells the image to become transparent for a specified color? Any other suggestions/solutions?
The value is on the form itself, not the conrols, it is called TransparencyKey
Set that to the color you wish to be transparent in the winforms designer, and any color that is equal to that color (in your form only) will be not be rendered.
Does your PNG's display correctly (with transparency) on a ImageList? Maybe your ImageList is set to 24bit RGB? Change to 32bit and that should help.
精彩评论