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 ...

+ Reply to Thread
Results 1 to 5 of 5

Bitmap to Clipboard problem

  1. Default 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?


  2. Default 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?
    >




  3. Default 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

  4. Default 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




  5. Default Re: Bitmap to Clipboard problem

    It works OK. Thank you Michael!


+ Reply to Thread

Similar Threads

  1. Copying a transparent 32 bit bitmap to the clipboard (on Windows)
    By Application Development in forum Graphics
    Replies: 2
    Last Post: 11-16-2007, 03:35 AM
  2. Copying a transparent 32 bit bitmap to the clipboard
    By Application Development in forum DOTNET
    Replies: 1
    Last Post: 10-26-2007, 09:22 AM
  3. Copying a transparent 32 bit bitmap to the clipboard
    By Application Development in forum CSharp
    Replies: 0
    Last Post: 10-26-2007, 09:16 AM
  4. Framework2 Clipboard bitmap problem solved
    By Application Development in forum DOTNET
    Replies: 0
    Last Post: 03-29-2007, 10:21 AM
  5. Bitmap sent to clipboard showing up as 32bpp DIB not 24bpp DIB?
    By Application Development in forum CSharp
    Replies: 0
    Last Post: 05-03-2006, 12:33 AM