C # DataGridView - Transparent Image

I am trying to populate a DataGridView cell with an image. The image is a 32-bit png with alpha transparency.

I can correctly display this image in a frame or in a Listview, but in a DataGridView, the image loses quality.

I tried to set the transparency of the transparent controls, but nothing works. I import the image into a resource file and then call it directly.

I have the feeling that I need to override the onpaint event to solve the transparency / color issue, but I'm not quite sure.

I would be grateful for any help!

The top image is that of a window with pictures and the bottom two in a DataGridView.

* Since I cannot use the image tag, see the following link for an example of a problem

http://bytes.com/attachments/attachment/2016d1245038555/imageissue.png

+3
source share
4 answers

I tested the GIF with a lower resolution and it looks acceptable. The PNG I used was 32-bit (with an 8-bit alpha channel), and I think it's just from the depth that the DataGridView image column can handle.

Thanks to everyone who offered their input. It is very much appreciated!

+1
source

I ran into the same problem. My 32-bit png image looked awful in a DataGridView. What I did was convert the png file to the .ico format (I used http://www.convertico.com/ ) and then added it to the grid.

displayCell.ValueIsIcon = True, DataGridViewImageCell .

. ...

+1

I'm not sure about this, but it looks like it might be a resize issue, not a transparency issue (or a resize / transparency issue). Try using a PNG file with exactly the same pixel dimensions as the size that it displayed in the DataGridView.

0
source

I had a problem using ImageList, as soon as I switched to an array of bitmaps, it worked fine.

0
source

Source: https://habr.com/ru/post/1719476/


All Articles