We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

.png image in a grid

Thread ID:





2649 Feb 6,2003 07:54 PM UTC Feb 18,2003 04:00 PM UTC WinForms 7
Tags: GridControl
Ivan Pelly
Asked On February 6, 2003 07:54 PM UTC

Hi - I have a derived GridStaticCellModel that I'm adding to .Model.CellModels. The context of the GridStaticCellModel (passed to the constructor) is a bitmap, loaded from a stream, which loads a .png graphic that has some transparency. Using the PrepareViewStyleInfo event, I set e.Style.CellType, and the graphic appears in the grid, but the transparency is gone - turned to white. Am I doing something wrong, or is this a limitation of the grid, or .NET? Thanks!

Administrator [Syncfusion]
Replied On February 6, 2003 08:03 PM UTC

Did you set the alpha-value for the Interior of the cell? Otherwise the cell background will be repainted with a solid color before the bitmap is drawn. Also, try the drawing code for the .png outside the grid in a regular form. Does it draw transparent then? If not, try ImageList.Draw - I believe ImageList has better support for transparency than Bitmap.Draw. Stefan

Ivan Pelly
Replied On February 11, 2003 07:46 PM UTC

I didn't try the alpha value for the cell interior - where does one set that? My code is using System.Grapics.DrawImage (according to the suggestion in the Grid Forum under the thread titled "Image Alignment in a Cell" dated 11/18/2002) to draw the image. Should I be using some other method? Thanks again, Ivan

Administrator [Syncfusion]
Replied On February 12, 2003 12:06 PM UTC

You can set the alphablend value with style.Interior = new BrushInfo(Color.FromArgb(alphaValue, color)); That will make cell have a transparent effect and display a image behind the grid as shown in the gridpad example. For drawing transparent images we found that Graphics.DrawImage does not support alphablending well. So what we use instead ImageList.Draw. For that to work you would have to create a image list, add the image and then call its Draw method. (I don't have a sample for this right now - I would have to look into closer first.) Best is if you try to get drawing code working fist on a regular form with no grid involved. Once you know this is working you can then use your drawing routine within the grid. Stefan

Administrator [Syncfusion]
Replied On February 14, 2003 02:17 PM UTC

I think Stefan had in mind trying to treat the entire bitmap as transparent in some manner. But if you just want to draw with a single transparent color on your bitmap, attached is a sample that does this. You will have to change the path to the bmp file to get it to run. It call the Bitmap.MakeTransparent to make a particular color transparent. Note that the bitmap was loaded with a Bitmap.FromFile call. I could not get the MakeTranparent call to work on a bitmap that came from an embedded resource.

Ivan Pelly
Replied On February 18, 2003 12:32 PM UTC

Actually I was trying to make use of the .png graphic format instead of a .bmp, since .png supports degrees of transparency (rather than just transparent or not). This makes for a better looking image, because the edges don't have that jagged bitmap look (I've attached a sample). I substituted in a .png image in the sample code provided in the 11/20/2002 post entitled "Image Alignment in a Cell", and the .png image draws fine, except that the areas that should be transparent are rendered as white, which is fine unless the backcolor in the cell isn't white. I was hoping to have the edges fade into whatever color the background happens to be. Thanks again.

Administrator [Syncfusion]
Replied On February 18, 2003 03:59 PM UTC

If you swap the bitmap1.bmp file with your TinyA.bmp file in the sample that I earlier attached to this thread, you do not see any white borders on the cell using white as the transparent color.

Administrator [Syncfusion]
Replied On February 18, 2003 04:00 PM UTC

should have written TinyA.png instead of TinyA.bmp....


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon