views:

975

answers:

3

I am attempting to populate a DataGridView cell with an image. The image is a 32bit png with Alpha Transparency.

I can get this image to display properly in a picturebox or a Listview but in the DataGridView the image loses quality.

I have tried setting various parts of the control to transparent but nothing seems to work. I import the image into resource file and then call it directly.

I have a feeling I need to override the onpaint event to resolve the transparency/color depth issue but I'm not entirely sure.

I would appreciate any help!

The top image is that from a picturebox and the bottom two are in the DataGridView.

*Since I am unable to use an image tag, please see the following link for an example of the problem

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

A: 

I'm not sure about this, but it appears that this might be a resizing issue rather than a transparency issue (or a problem with the resizing/transparency interaction). Try using a PNG file that has exactly the same pixel-by-pixel dimensions as the size to which it's rendered in the DataGridView.

MusiGenesis
I wish that were it but I can make the cell height the exact size or larger than the image and it still appears as shown in the example.
NSH
Can you post a code sample, or better yet a link to a simple project that shows this problem? I'm curious about this because it's a weird problem, but I don't feel like figuring out the basics of loading images into a DataGridView. It looks kind of like the DataGridView is trying (and failing miserably) to draw some sort of border effect around the image.
MusiGenesis
Add a DataGridView control to your form.Add the following code to formload: Bitmap testImage = new Bitmap(@"C:\pathtoyourimage.png"); dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; DataGridViewImageColumn imageColumn = new DataGridViewImageColumn(); dataGridView1.Columns.Add(imageColumn); dataGridView1.Rows.Add(testImage);
NSH
@NSH: I think your problem is either something weird about your computer or something weird about the PNG file you're using. Using your sample code (thank you), I was able to load a bunch of different PNG files (all with trasnparency) in the DataGridView, and they all looked perfect and normal (no weird artifacts). Post a link to your original PNG file and I'll see what that looks like on my computer.
MusiGenesis
I have tested with a lower resolution gif and it looks acceptable. The PNG I was using is 32-Bit (with 8 bits alpha channel) and I think this is simply out of the depth that the DataGrideView Image Column can handle.
NSH
A: 

I have tested with a lower resolution gif and it looks acceptable. The PNG I was using is 32-Bit (with 8 bits alpha channel) and I think this is simply out of the depth that the DataGrideView Image Column can handle.

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

NSH
A: 

I came across the same problem. My 32 bits png image looked horrible in a DataGridView. What I did is convert my png file to the .ico format (I used http://www.convertico.com/), and then added it to the grid.

What I did is set displayCell.ValueIsIcon = True to make the DataGridViewImageCell treat my image as an Icon.

And that did it for me. The icons look good now...

Saab