Bitmap to Clipboard problem - DOTNET
This is a discussion on Bitmap to Clipboard problem - DOTNET ; Have a problem with clipboard. Using the standard way for copying the
image data:
read the image into "myBitmap"
copy the image into clipboard:
DataObject myData = new DataObject();
myData.SetData( DataFormats.Dib,true,myBitmap);
Clipboard.SetDataObject(myData,true);
Now: pasting the image from the clipboard works ...
-
Bitmap to Clipboard problem
Have a problem with clipboard. Using the standard way for copying the
image data:
read the image into "myBitmap"
copy the image into clipboard:
DataObject myData = new DataObject();
myData.SetData( DataFormats.Dib,true,myBitmap);
Clipboard.SetDataObject(myData,true);
Now: pasting the image from the clipboard works with most programs
(e.g. MS Paint, Outlook). But it doesn't work with OpenOffice
There
is no "Paste" function active...
The there is only one entry in clipboard formats after above operation:
MetaFilePict - DeviceIndependentBitmap
There is no problem with OpenOffice when image is copied from MS Paint.
So checked the clipboard formats after copying the image into clipboard
in MS Paint. There are two formats:
MetaFilePict - DeviceIndependentBitmap
Embed Source - Object Descriptor
Does the second entry causes the problem? How to resolve that problem?
-
Re: Bitmap to Clipboard problem
If you place a CF_DIB clipboard format to the cliboard with
your code, the clipboard will synthesize the following formats:
CF_BITMAP, CF_DIB5, CF_PALETTE
It will not synthesize a CF_METAFILEPICT format from your DIB.
You must create a Metafile object and place either a CF_ENHMETAFILE
or a CF_METAFILEPICT object on the clipboard.
The clipboard will synthesize either a CF_ENHMETAFILE or a CF_METAFILEPICT
format depending upon which one of these you placed on the clipboard.
"geo24" <flyfish@poczta.onet.pl> wrote in message
news:1131954306.167849.150010@f14g2000cwb.googlegroups.com...
> Have a problem with clipboard. Using the standard way for copying the
> image data:
>
> read the image into "myBitmap"
> copy the image into clipboard:
>
> DataObject myData = new DataObject();
> myData.SetData( DataFormats.Dib,true,myBitmap);
> Clipboard.SetDataObject(myData,true);
>
> Now: pasting the image from the clipboard works with most programs
> (e.g. MS Paint, Outlook). But it doesn't work with OpenOffice
There
> is no "Paste" function active...
>
> The there is only one entry in clipboard formats after above operation:
>
>
> MetaFilePict - DeviceIndependentBitmap
>
> There is no problem with OpenOffice when image is copied from MS Paint.
>
> So checked the clipboard formats after copying the image into clipboard
>
> in MS Paint. There are two formats:
>
> MetaFilePict - DeviceIndependentBitmap
> Embed Source - Object Descriptor
>
> Does the second entry causes the problem? How to resolve that problem?
>
-
Re: Bitmap to Clipboard problem
Could you show how to do that in c# having just a jpg file?
Geo24
--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
-
Re: Bitmap to Clipboard problem
There is a bug in the .Net implementation of SetData for the metafile
clipboard format.
Use the following instead:
// declarations
[DllImport("user32.dll")]
static extern IntPtr SetClipboardData(uint uFormat, IntPtr hMem);
[DllImport("user32.dll")]
static extern bool OpenClipboard(IntPtr hWndNewOwner);
[DllImport("user32.dll")]
static extern bool EmptyClipboard();
[DllImport("user32.dll")]
static extern bool CloseClipboard();
public static uint CF_ENHMETAFILE = 14;
....
Bitmap img = (Bitmap)Bitmap.FromFile(@"c:\TestImage.jpg",true);
// create graphics object for metafile
Graphics g = CreateGraphics();
IntPtr hdc = g.GetHdc();
Metafile meta = new Metafile(@"SampleMetafilegdiplus.emf", hdc );
g.ReleaseHdc(hdc);
g.Dispose();
// create a metafile image from the jpeg image
g = Graphics.FromImage(meta);
g.DrawImage(img, new Point(0,0));
g.Dispose();
// get a handle to the metafile
IntPtr hEmf = meta.GetHenhmetafile();
meta.Dispose();
// open the clipboard
OpenClipboard(this.Handle); // your Form's Window handle
EmptyClipboard();
// place the handle to the metafile on to the clipboard
SetClipboardData(CF_ENHMETAFILE, hEmf);
CloseClipboard();
....
"Geo24" <flyfish@poczta.onet.pl> wrote in message
news:uw2%233R96FHA.3416@TK2MSFTNGP15.phx.gbl...
> Could you show how to do that in c# having just a jpg file?
>
> Geo24
>
> --
> Sent via .NET Newsgroups
> http://www.dotnetnewsgroups.com
-
Re: Bitmap to Clipboard problem
It works OK. Thank you Michael!
Similar Threads
-
By Application Development in forum Graphics
Replies: 2
Last Post: 11-16-2007, 03:35 AM
-
By Application Development in forum DOTNET
Replies: 1
Last Post: 10-26-2007, 09:22 AM
-
By Application Development in forum CSharp
Replies: 0
Last Post: 10-26-2007, 09:16 AM
-
By Application Development in forum DOTNET
Replies: 0
Last Post: 03-29-2007, 10:21 AM
-
By Application Development in forum CSharp
Replies: 0
Last Post: 05-03-2006, 12:33 AM