Skip to content

Conversation

@emmauss
Copy link
Contributor

@emmauss emmauss commented Oct 27, 2025

What does the pull request do?

This PR allows users to directly get a Bitmap bitmap from clipboard if a supported image format is available. This is in addition to the currently supported text and file formats. This only supports images copied to clipboard directly, and not from a file in disk. Depending on platform, we choose the most suitable format among the available formats as the default Image data format.
On Windows, the priority is; png > jpg > bmp.
On Android, we attempt to load the file in clipboard as a Bitmap, since apps can decide not to use full mimetypes when copying files to clipboard.

What is the current behavior?

Users can't retrieve image data formats from clipboard on some platforms without creating a DataFormat of byte matching the system type of the image data. The process would normally be like this

  1. Get the formats supported for the data in the clipboard.
  2. Find a suitable format they what
  3. Create a DataFormat<byte> with the format name and a internal hidden AppId
  4. Retrieve the data
  5. Load that data as a bitmap.

The format names are also platform specific, so each platform would need to have their own image loading logic.

What is the updated/expected behavior with this PR?

Common image formats that we know skia supports on all platforms can now be retrieved directly as a Bitmap instance.
For example, retrieving a image in clipboard can be easily done like this;

using var data = await clipboard.TryGetDataAsync();
Bitmap? source = null;
if (data != null)
{
    source = await data!.TryGetValueAsync(DataFormat.Image);
}
ClipboardImage.Source = source;

How was the solution implemented (if it's not obvious)?

Checklist

Breaking changes

Obsoletions / Deprecations

Fixed issues

@emmauss emmauss added enhancement backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch labels Oct 27, 2025
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0059590-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@danipen
Copy link

danipen commented Oct 27, 2025

is this feature going to be supported in the other platforms? (macOS, Linux ...)

@emmauss
Copy link
Contributor Author

emmauss commented Oct 28, 2025

is this feature going to be supported in the other platforms? (macOS, Linux ...)

Linux, Mac and iOS will be supported

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0059600-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@emmauss emmauss changed the title Win32 | Android - Support reading images from clipboard Win32 | Android | Browser - Support reading images from clipboard Oct 28, 2025
@emmauss
Copy link
Contributor Author

emmauss commented Oct 28, 2025

Added Browser support

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0059606-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

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

Labels

backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants