0

I create an application support copy an image to clip board and parse to pdf, excel or auto card file. I have an issue : copy an image PNG, when parse it loses transparency , it's transparency to be gray Some body help me?

My code :

Bitmap managerStampBitmap = new Bitmap(tc.Path);
using (MemoryStream stream = new MemoryStream())
            {
                managerStampBitmap = Commons.ResizeImage(managerStampBitmap, 38, 38);
                managerStampBitmap.Save(stream, ImageFormat.Png);
                System.Windows.Forms.DataObject data = new System.Windows.Forms.DataObject("PNG", stream);
                System.Drawing.Image image = System.Drawing.Image.FromStream(stream, true, true);
                data.SetImage(image);
                System.Windows.Forms.Clipboard.Clear();
                System.Windows.Forms.Clipboard.SetDataObject(data, true);

            }

enter image description here

Anh Vũ
  • 21
  • 8
  • 1
    https://stackoverflow.com/q/44177115/10216583 and http://csharphelper.com/blog/2014/09/paste-a-png-format-image-with-a-transparent-background-from-the-clipboard-in-c/ –  Jun 17 '20 at 09:58
  • i refer them but i can resolve my issue – Anh Vũ Jun 30 '20 at 02:16
  • Your issue is probably that the program you're pasting it _into_ doesn't know the "png" type and is using the `data.SetImage` one instead. I showed a workaround for that using DIB format, but if that doesn't work either, then maybe the application **might simply not support transparent image paste at all**. – Nyerguds Aug 31 '20 at 09:53
  • Also note, the `image` variable you make is useless; you can just take the `managerStampBitmap`. Also, any images/bitmaps should be inside a `using` statement just like the stream. – Nyerguds Aug 31 '20 at 09:54

0 Answers0