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.
Unfortunately, activation email could not send to your email. Please try again.

How to draw a transparent png

Thread ID:

Created:

Updated:

Platform:

Replies:

108005 Mar 29,2013 08:02 PM Apr 19,2013 12:02 AM ASP.NET Web Forms (Classic) 3
loading
Tags: PDF
Jeff Gilbert
Asked On March 29, 2013 08:02 PM

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

George Livingston [Syncfusion]
Replied On April 2, 2013 12:35 AM

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


Jeff Gilbert
Replied On April 18, 2013 10:17 AM

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

George Livingston [Syncfusion]
Replied On April 19, 2013 12:02 AM

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


CONFIRMATION

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.

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.

;