Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@bclehmann
Copy link
Member

@bclehmann bclehmann commented Nov 29, 2025

Now that AvaloniaUI/Avalonia#19930 has been merged I can tick a feature off my list (5 years later πŸ™ƒ). We'll have to think about how we ought to disable this behaviour on earlier Avalonia versions, or just require a version that has this.

This implementation is hacky and I haven't cleaned it up yet, I mostly wanted to see what the capabilities were and what we would have to do to support it. It's mostly the same as other implementations (call GetImageBytes, turn it into a platform-specific image, and then pass it to a platform-specific function).

The problem is that Avalonia requires we pass them a bitmap, which even with the device-independent-bitmap (DIB) that we have implemented is only a pseudo-standardized format. That wouldn't be a problem if Avalonia weren't cross-platform, where the preferred byte order of bitmaps can differ. Plus Avalonia seems to be ignoring the pixelFormat parameter, at least on Mac where I'm currently testing, so switching byte orders must be done by hand.

On an ARM Mac it seems that all we need to do is strip out the DIB header and it will have the correct colours. But I would want to test on Windows and Linux as well to make sure it does the right thing everywhere. I'm hoping that x86 vs ARM doesn't change the byte order for any OS, because I can't test Windows on ARM, and testing Mac on x86 or Linux on ARM is inconvenient but doable for me.

Once I've done that I'd like to think about how we ought to change this code, I would probably like to make the BitmapHeader struct internal again and just expose a method to get only the pixel array for a bitmap. And then come to a decision about how we release this and if we require a newer Avalonia version.

@bclehmann
Copy link
Member Author

With this only Maui and Blazor would be lacking this functionality.

Maui likely won't happen anytime soon, since they (to my knowledge) don't support anything but text on their clipboard. Presumably because of their mobile-focused roots.

Blazor doesn't have a right-click menu at all right now, I don't know why that is since I don't think I've worked on Blazor features.

@bclehmann
Copy link
Member Author

bclehmann commented Nov 30, 2025

It appears that the Windows implementation is partially borked, pasting into an image editor like Paint works well. But pasting into github tells me the file is empty. So I might wait a little bit.

EDIT: I'm diving deeper, my hunch is that it's generating a correct OLE clipboard entry that Paint knows how to handle. But the traditional CF_DIB is borked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant