I am taking an existing PNG image file that has a transparent portion, adding some text on top (using Graphics.DrawString()) before saving the image back to the disk.
I would like to also save the image to the clipboard. However, when I try to paste the resulting image into MS Paint, the transparent regions are light gray. The saved file however retains the transparency correctly.
This is what I currently have:
//reads file into an System.Drawing.Image
FileStream fs = new FileStream(fileLocation, FileMode.Open, FileAccess.Read);
Image image = Image.FromStream(fs);
fs.Close();
//add text to image via System.Drawing.Graphics
Bitmap myBitmap = new Bitmap(image);
Graphics g = Graphics.FromImage(myBitmap);
g.DrawString(textToAdd, new Font("Tahoma", 14), System.Drawing.Brushes.Black, new PointF(0, 0));
//save modified image back to disk (transparency works)
myBitmap.Save(fileLocation, System.Drawing.Imaging.ImageFormat.Png);
//Copy to clipboard (transparent areas are now gray)
System.Windows.Forms.Clipboard.SetImage(myBitmap);