gregdosborne
-
Posts
3 -
Joined
-
Last visited
Posts posted by gregdosborne
-
-
My primary graphics tool is Paint.Net, but I have found an inadequacy for what I am doing.
Paint.NET copies data to the clipboard in the following formats
PaintDotNet.MaskedSurface
Format17
System.Drawing.Bitmap
Bitmap
DeviceIndependentBitmap
found by examining data.GetFormats() in C#. I cannot use PaintDotNet.MaskedSurface in my application and the others don't provide full transparency information for PNGs. Is there a way to have Paint.NET copy data to the clipboard using "PNG" format?
In my app, I can copy an image into the clipboard using the following code, and all transparency information is retained.
using (MemoryStream stream = new MemoryStream())
{
_Bitmap.Save(stream, ImageFormat.Png);
var data = new DataObject("PNG", stream);
Clipboard.Clear();
Clipboard.SetDataObject(data, true);
}
and I can read the same from the clipboard using the following
IDataObject data = Clipboard.GetDataObject();
if (data.GetFormats().Contains("PNG")){
MemoryStream ms = (System.IO.MemoryStream)data.GetData("PNG");
_Bitmap = (Bitmap)Bitmap.FromStream(ms, true);
}
Can this be accomplished in Paint.NET, or can an extension be created that will do this?
Thanks in advance...
-
It is not the file, it is a png image. I know the difference.
I copy it using .net.
Clipboard.SetData("PNG", image);
image is a standard 32bpp png which opens fine in Paint.NET and renders fine in .net Windows.Forms.
Clipboard.SetImage(image);
does the job, but the image loses its transparency when pasted, so it's of no use.
So, why does Paint.NET not recognize the "PNG" Clipboard format?
To properly paste a PNG image to the clipboard, do the following
using (MemoryStream stream = new MemoryStream())
{
_Bitmap.Save(stream, ImageFormat.Png);
var data = new DataObject("PNG", stream);
Clipboard.Clear();
Clipboard.SetDataObject(data, true);
}
This should take care of your problems.
PNG format in clipboard
in Paint.NET Discussion and Questions
Posted
Thanks Rick, but I was looking for a way to paste an entire image into my application from Paint.NET.