|
Hi guys,
I've been digging around for information on how to get a IntPtr device bitmap dumped back into a WritableBitmap file. Going to keep working on the problem, but if there's any suggestions throw them here. Here's a bit of scaffolding explaining what I want
to do.
internal class Native {
[DllImport("user32.dll", EntryPoint = "CloseClipboard", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool CloseClipboard();
[DllImport("user32.dll", EntryPoint = "GetClipboardData", SetLastError = true)] public static extern IntPtr GetClipboardData(ClipboardFormat uFormat);
[DllImport("user32.dll", EntryPoint = "IsClipboardFormatAvailable", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool IsClipboardFormatAvailable(ClipboardFormat format);
[DllImport("user32.dll", EntryPoint = "OpenClipboard", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool OpenClipboard([In] IntPtr hWndNewOwner);
}
public enum ClipboardFormat : uint {
/// <summary>
/// A handle to a bitmap (HBITMAP).
/// </summary>
CF_BITMAP = 2
}
code.
IntPtr p = IntPtr.Zero;
try{
Native.OpenClipboard(p);
if (Native.IsClipboardFormatAvailable(ClipboardFormat.CF_BITMAP))
{
IntPtr p = Native.GetClipboardData(ClipboardFormat.CF_BITMAP);
if (p != IntPtr.Zero)
{
// stuck here - how to convert IntPtr to a useful stream
// .NET has a Image.FromHbitmap(IntPtr)
ImageTools.IO.Decoders.AddDecoder<BmpDecoder>();
ImageTools.IO.Decoders.AddDecoder<PngDecoder>();
BmpDecoder decoder = new BmpDecoder();
ImageTools.ExtendedImage image = new ImageTools.ExtendedImage();
decoder.Decode(image, stream);
}
}
finally
{
Native.CloseClipboard();
}
|