There is a Windows program that generates PNG from HTML via WebBrowser
.
This PNG must then be inserted into a PDF that is opened in Adobe Acrobat Reader DC as a stamp.
Below is a code that draws a PNG and sends it to the clipboard.
static void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
var webBrowser = (WebBrowser)sender;
Bitmap bitmap = new Bitmap(webBrowser.Width, webBrowser.Height, PixelFormat.Format32bppArgb);
webBrowser.DrawToBitmap(bitmap, new Rectangle(0, 0, bitmap.Width, bitmap.Height));
bitmap.MakeTransparent(Color.White);
Clipboard.SetImage(bitmap);
}
The image is clipboard with a gray background, although when saved via bitmap.Save("img.png", ImageFormat.Png);
the background is indeed transparent.
using (MemoryStream stream = new MemoryStream())
{
bitmap.Save(stream, ImageFormat.Png);
var data = new DataObject("PNG", stream);
Clipboard.Clear();
Clipboard.SetDataObject(data, true);
}
Tried saving the image to a MemoryStream
and sending it to the clipboard as a DataObject
. In this case, the clipboard is left empty.
Thanks to Nyerguds, I know that by default the Windows clipboard does not preserve transparency. But due to lack of experience, I can't figure out how to apply it myself.
How can I keep the transparency of the image for later pasting?