Issue 85661 - Cannot paste (image) from clipboard copyed from .net
Summary: Cannot paste (image) from clipboard copyed from .net
Alias: None
Product: General
Classification: Code
Component: code (show other issues)
Version: OOo 2.3.1
Hardware: All Windows XP
: P3 Trivial with 11 votes (vote)
Target Milestone: ---
QA Contact:
: 60445 95178 (view as issue list)
Depends on:
Reported: 2008-01-29 05:12 UTC by Unknown
Modified: 2016-03-29 04:54 UTC (History)
5 users (show)

See Also:
Latest Confirmation in: ---
Developer Difficulty: ---

Tiny Test App to demonstrate clipboard issue (7.81 KB, application/x-compressed)
2008-03-06 15:02 UTC, sebcrabbe
no flags Details

Note You need to log in before you can comment on or make changes to this issue.
Description Unknown 2008-01-29 05:12:47 UTC
Cannot paste (image) to Ooo from clipboard copyed from .net(1.1 to 3.5)

/* C#
using System;
using System.Drawing;
using System.Windows.Forms;
private void button1_Click(object sender, System.EventArgs e)
   Bitmap bmp = new Bitmap(@"c:\windows\system32\setup.bmp");
   Clipboard.SetDataObject(bmp, true); /* Clipboard.SetImage(bmp); */
 openoffice cannot use paste
Comment 1 thorsten.martens 2008-01-30 10:56:05 UTC
TM->JSK: Basic-Problem ? No problem reproducible when using UI. Please have a
look, thanks !
Comment 2 kpalagin 2008-01-31 19:37:14 UTC
Confirming with 2.3 - as described.

Also can be easily reproduced with Paint .Net -
Comment 3 kpalagin 2008-01-31 19:38:05 UTC
*** Issue 60445 has been marked as a duplicate of this issue. ***
Comment 4 watersrw 2008-01-31 19:53:12 UTC
This should be a duplicate of the earlier one, and that one has more information.
Comment 5 robbk 2008-03-06 10:38:17 UTC
We also have this problem. When copying from Paint.NET the "Paste" menu item is
greyed out in OOo, but not in other applications.
Comment 6 sebcrabbe 2008-03-06 15:02:48 UTC
Created attachment 51940 [details]
Tiny Test App to demonstrate clipboard issue
Comment 7 sebcrabbe 2008-03-06 15:10:32 UTC
Shame people don't check the creation time of issues, but as the issue is still 
unresolved and it appears people are having trouble recreating it (not 
having .net), here is a simple test app to demonstrate it. The code for it is 
as below:

Imports System.Drawing

Public Class Form1
    Dim clipBMP As Bitmap

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub createBMP(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles createBMPB.Click
            'a very simple test routine to illustrate issue 
            'note you may need to import system.drawing
            'the below makes use of GDI+ calls wrapped up in .net objects

            If Not (clipBMP Is Nothing) Then clipBMP.Dispose() 'otherwise 
you'll get a memory leak
            clipBMP = Nothing

            'create a bitmap and get a handle on the graphics
            clipBMP = New Bitmap(250, 250) 'instantiate object and specifiy size

            Dim gr As Graphics = Graphics.FromImage(clipBMP) 'create a graphics 
object from the bitmap

            'draw stuff on the bitmap
            Dim r As New Rectangle(10, 100, 230, 50)
            Dim p As New Pen(Color.Black, 2)
            gr.DrawRectangle(p, r)
            gr.FillRectangle(Brushes.LightSteelBlue, r)

            Dim strFormat As New StringFormat
            strFormat.Alignment = StringAlignment.Center
            strFormat.LineAlignment = StringAlignment.Center
            gr.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
            gr.DrawString("Hello Open Office", New Font("Arial Black", 14), 
Brushes.Black, r, strFormat)

            'lets clear all the object as not all of them are managed and 
handled by GC

            'now we cause the picture box to be redrawn and as we handle
            'the paint event we'll use the above bmp ;)

        Catch ex As Exception
        End Try
    End Sub

    Private Sub copyBMPB_Click(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles copyBMPB.Click
            If (clipBMP Is Nothing) Then
                MsgBox("Please create a bitmpa first using the create button")
                'create a dataobject 
                Dim dataObj As DataObject = New DataObject

                'add the bitmap
                dataObj.SetData(DataFormats.Bitmap, True, clipBMP)

                'copy it to the clipboard
                Clipboard.SetDataObject(dataObj, True)

                'now try and paste it into a document. you can under wordpad, 
microsoft office etc.
                'but the paste icon does not appear in openoffice
            End If
        Catch ex As Exception
        End Try
    End Sub

    Private Sub bmpP_Paint(ByVal sender As Object, ByVal e As 
System.Windows.Forms.PaintEventArgs) Handles bmpP.Paint
            'if we have a bmp we'll use it to draw the panel
            If Not (clipBMP Is Nothing) Then e.Graphics.DrawImageUnscaled
(clipBMP, 0, 0)
        Catch ex As Exception
        End Try
    End Sub
End Class

It's all simple stuff really, and the library calls are used by all .net 
languages so it isn't a vb issue. My guess would be that open office doesn't 
like something in the header information of the clipboard bitmap, perhaps 
someone could test that? 

I'd point out that as Linux does'nt use GDI+ it uses it's own 2D system that 
running this under Linux would not be a proper test, ohh and it stands to 
reason that you'll nedd .net installed

P.S. Win Vista used WPF for display and uses GDI+ under emulation so it may 
behave differently under win Vista
Comment 8 kpalagin 2008-04-07 19:04:22 UTC
please consider this issue for 3.0, if possible.

Thanks a lot.
Comment 9 arj03 2008-04-21 11:40:30 UTC
Additional comments.

Copying to wordpad first and then copying that to open office works.

Microsoft seems to be aware of the problem, and it appears to be a problem in
the .Net clipboard implementation:

Still it would be very nice if this could be supported.
Comment 10 sebcrabbe 2008-04-21 13:37:51 UTC
Im not so sure that microsoft issue is relevant. That issue is to do with 
putting information onto the clipboard in metafile format, which you specify in 
the dataFormat parameter in the setDataObject command. As we are specifying an 
image format (dataFormats.Bitmap) and not the metafile format i fail to see how 
that would be applicable.
Comment 11 joerg.skottke 2008-06-17 10:05:36 UTC
@Philipp: Is this something for you?
I believe it could make a nice enhancement.
Comment 12 philipp.lohmann 2008-06-17 11:23:12 UTC
@hro: windows clipboard is yours nowadays I think ?
Comment 13 hennes.rohling 2008-06-17 15:32:16 UTC
The .NET Clipboard implementation just puts two formats into the OLE clipboard
which are visible for the OLE clipboard: "System.Drawing.Bitmap" which is not
very usefull for non .NET applications and CF_BITMAP which contains a native GDI
handle but not any flat storage with the image data.

Windows internal clipboard implementation only does a conversion to CF_DIB for
the old Win 3.x based clipboard API.

OOo uses the OLE clipboard implementation (as .NET does) but only accepts
formats where data is in a flat storage or in a metafile handle.

Native device dependent bitmap handles are currently not supported as all know
applications provide a CF_DIB (device independent bitmap) in a memory stream to
the OLE clipboard but no application provided a CF_BITMAP format.

Naturally OOo platform independent application code isn't able to deal with
native GDI object handles, so we need an implementation in the system clipboard
layer that does a conversion from a bitmap handle to the bitmap data.
Comment 14 eric.savary 2008-10-20 15:42:48 UTC
*** Issue 95178 has been marked as a duplicate of this issue. ***
Comment 15 robbk 2009-06-08 12:46:24 UTC
Tested in OOo 3.1. Problem still occurs.
Comment 16 kai.sommerfeld 2009-07-13 13:01:40 UTC
hdu: Please take over.
Comment 17 tsjoecha 2009-11-19 09:08:11 UTC
Please consider existing files as well: in some ms documents images
were pasted, and when we try to open the files in OOo, the images disappear.
Comment 18 paulojbe 2010-03-17 13:38:35 UTC
Tested in OOo 3.2. Problem still occurs.
Comment 19 stuartprescott 2010-07-14 11:26:42 UTC
As a work-around for those developing .NET applications who want to be able copy
images to the clipboard and have OOo cope with this, try deliberately sticking a
DIB on the clipboard instead (or as well as) the System.Drawing.Bitmap.

e.g. the following code will allow you to place a system.drawing.bitmap "bmp" on
the clipboard in an OOo-compliant fashion.

      Dim ms As New IO.MemoryStream()
      Dim ms2 As New IO.MemoryStream()
      bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)
      Dim b() As Byte = ms.GetBuffer()
      ms2.Write(b, 14, CInt(ms.Length - 14))
      ms.Position = 0
      Dim dataObject As New DataObject()
      dataObject.SetData(DataFormats.Bitmap, bmp)
      dataObject.SetData(DataFormats.Dib, ms2)
      Clipboard.SetDataObject(dataObject, False)

(Adapted from
Comment 20 damjan 2016-03-29 04:54:27 UTC
The bug can be reproduced with the test app attached on OOo 3.2.0, but cannot be reproduced on AOO 4.1.2 or SVN trunk. It must have been fixed some time ago. Resolving fixed.