简体   繁体   中英

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_position);

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?

该值在窗体本身上,而不是在控件上,它称为TransparencyKey ,将其设置为您希望在winforms设计器中透明的颜色,并且与该颜色相等的任何颜色(仅在您的窗体中)都不会呈现。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM