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

How to draw a transparent png

Hello,
I am trying to draw a png that has a transparent background on a page using ASP.NET pdf.  The transparent pixels come out black. Here is what I'm trying:
_______________________________________________________________________
            bmp = new System.Drawing.Bitmap("c:\\Temp\\Bitmap3.png");
            var g = (page as PdfPageBase).Graphics;
            PdfImage pdfImg = new PdfBitmap(bmp);
            g.DrawImage(pdfImg, location.X, location.Y);
_______________________________________________________________________

Do I need to create a PdfImageMask or a PdfColorMask to make this work?

I've been looking at your documentation here and here

The attachment contains the png I am working with and the pdf after I've inserted the png on page 8.

What am I missing?

Thanks,
Jeff


Temp_65569607.zip

3 Replies

GL George Livingston Syncfusion Team April 2, 2013 04:35 AM UTC

Hi Jeff,

Thank you for using Syncfusion product.

We are not able to reproduce the issue using the version 11.1.0.21, herewith we have attached the sample with which we tried to reproduce the issue. Can you please provide us a sample or modify this sample to reproduce the issue. Also please let us know the Essential studio version you are using.

InsertImage.zip

Please let us know if you have any questions.

Regards,

George



JG Jeff Gilbert April 18, 2013 02:17 PM UTC

I figured out the problem.  This works to create a transparent png:
private PdfImage DrawImage(PdfPageBase page, Bitmap bmp, RectangleF location)
{
    var ms = new MemoryStream();
    bmp.Save(ms, ImageFormat.Png);
    var pdfImg = new PdfBitmap(ms);
    var g = (page as PdfPageBase).Graphics;
    g.DrawImage(pdfImg, location.X, location.Y);

This is the way I was doing it before.  It creates an image with a white background:
private PdfImage DrawImage(PdfPageBase page, Bitmap bmp, RectangleF location)
{
    var g = page.Graphics;
    PdfImage pdfImg = new PdfBitmap(bmp);
    g.DrawImage(pdfImg, location.X, location.Y);
 
Cheers,
Jeff


GL George Livingston Syncfusion Team April 19, 2013 04:02 AM UTC

Hi Jeff,

 

Thank you for your update.

 

We are glad to hear that the issue has been resolved.

 

Please let us know if you have any concerns.

 

Regard,

George


Loader.
Up arrow icon