Skip to content

Windows: Clipboard SetValueAsync(DataFormat.Bitmap, bmp) generates invalid CF_DIB, CF_BITMAP entries #20183

@bclehmann

Description

@bclehmann

Describe the bug

If you use this API to copy an image to the clipboard on Windows you will get something that is only pastable in certain applications (I found that it works in MS Paint and Paint.NET, but not when pasting into Chrome). This is reproducible in the Avalonia Control Gallery.

If you use Clipview (I'm certain there's a better program, but it's what I'm familiar with) you get the following objects:

  • CF_MAX: Size 2.8 MB (seems to be meaningless contents)
  • CF_BITMAP: Size 0 bytes
  • 49171 (OLE Private Data): 168 bytes, if I were to guess this is why MS Paint and similar programs can open it just fine
  • CF_DIB: 2.8 MB (confirmed invalid bitmap through a hex dump) EDIT: This actually does look valid, I hadn't realized clipboard bitmaps use the BITMAPINFO header rather than the traditional DIB file header
  • 49161 (DataObject): 8 bytes

I first noticed this issue on ScottPlot/ScottPlot#5167.

Thank you for all that you do, we plan to make use of this feature in ScottPlot as soon as this is resolved. It seems to work fine on Mac, and I expect we'll be testing on Linux sometime this coming week.

To Reproduce

Running on Windows 11 23H2 Build 22631.6199 on x86-64.

  1. Open the Avalonia Control Gallery (tested on 5198744)
  2. Open the Clipboard demo
  3. Click "Copy Image to Clipboard"
  4. Observe that the resulting image is previewable in the Windows clipboard menu (Win + V) and is pastable into MS Paint, but is not pastable into Chrome (I'm on Chrome version 142.0.7444.176).

If you go to https://evercoder.github.io/clipboard-inspector/ you will see something like this:

Image

If one pastes through the Win + V menu it appears to work as expected, presumably because that menu converts formats around.

Expected behavior

Copying an image to the clipboard should be pastable in all programs that support pasting images.

Avalonia version

11.3.9 and commit 5198744 (master at the time of this report)

OS

Windows

Additional context

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions