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

pdfimage transparency lost when inserted in pdf

Hi,

I am using this basic code to insert an image that is generated on-the-fly, with some transparency added with a common wpf transparency function

Bitmap myBitmap = somegenerationfunctionhere();
myBitmap.MakeTransparent(System.Drawing.Color.White); // yes, my image does have some white !
PdfBitmap myPdfBitmap = new PdfBitmap(myBitmap);
page.Graphics.DrawImage(myPdfBitmap, ...);

.. and instead of having some transparency all the white becomes black. I am not doing any other manipulation mon myBitmap between the transpoarency and passing it to pdfimage
What is wrong in the code above ? or bug ?

Thanks,
F

3 Replies

GR Gayathri Ramalingam Syncfusion Team November 30, 2016 02:31 PM UTC

Hi Fabrice, 
 
Thank you for using Syncfusion products.  
On analyzing your code snippet, we came to know that you have directly passed Bitmap image to PdfBitmap. You have to save the bitmap into memory stream before passing it to PdfBitmap. 
 
Please find the below code snippet, 
Bitmap bitmap = somegenerationfunctionhere(); 
 
bitmap.MakeTransparent(System.Drawing.Color.White); 
 
MemoryStream imageStream = new MemoryStream(); 
 
bitmap.Save(imageStream,System.Drawing.Imaging.ImageFormat.Png); 
 
PdfBitmap image = new PdfBitmap(imageStream);    
       
Please find the sample from the below link, 
 

Please let us know if you need further assistance.  

With Regards, 
Gayathri R 



FF fff December 1, 2016 08:43 AM UTC

Hi Gayathri,

(My code was not passing "directly", but initially using an Image as some SF examples ; this was a simplified version here, but it was not working either anyway)

But your method with a Stream, permitting to force a png format supporting transparency, works perfectly. Job done!

Thanks a lot,
Fabrice


GR Gayathri Ramalingam Syncfusion Team December 2, 2016 09:53 AM UTC

Hi Fabrice 
 
We are glad that the issue is resolved at your end and please let us know if you need further assistance. 
 
With Regards, 
Gayathri R 


Loader.
Live Chat Icon For mobile
Up arrow icon