How to make image transparent


https://www.nevron.com/Forum/Topic14332.aspx
Print Topic | Close Window

By Kirk Kanjian - 2 Years Ago
Hello,

I am using the following code to download the renderings as image from NThinDiagramControl.
I need to set the Transparency for the image.
Please let me know how can i set it.

Dim image As INImage = NThinDiagramControl1.GetImage(imageFormat, New NSize(txtImgPixelSize.Text.Trim, txtImgPixelSize.Text.Trim), New NResolution(200, 200))

Thanks
By Nevron Support - 2 Years Ago
Hello Kirk,

Generating transparent PNG images is not supported out of the box, but you can try the following workaround:
1. Create a PNG image format with a pixel format that supports transparency
2. Generate a raster image
3. Use the MakeTransparent method of the .NET bitmap object to make the white pixels transparent
4. Save the bitmap to file or stream

Following is a code example:

NPngImageFormat pngFormat = new NPngImageFormat();
pngFormat.PixelFormat = System.Drawing.Imaging.PixelFormat.Format32bppArgb;

NRasterImage image = NThinDiagramControl1.GetImage(pngFormat) as NRasterImage;
image.Bitmap.MakeTransparent(Color.White);
image.Bitmap.Save(@"C:\web-image.png");