Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create ToWriteableBitmap() method similar to ToBitmapSource() to support Avalonia bitmap Images #1743

Open
Ruben2776 opened this issue Oct 28, 2024 · 1 comment

Comments

@Ruben2776
Copy link

Ruben2776 commented Oct 28, 2024

Is your feature request related to a problem? Please describe

No built-in bitmap conversion for AvaloniaUI, like WPF has.

Describe the solution you'd like

I would like to be able to convert a MagickImage to an Avalonia WriteableBitmap, with an easy extension method, just like WPF has.

Describe alternatives you've considered

I'm currently achieving it by setting the format as Png and writing it to a MemorySteam, but that is inefficient. I'm looking for a similar way of correctly converting the pixel data, to use for an Avalonia image.
I've tried doing it myself, but unfortunately I don't understand this well enough, as I've run into multiple issues such as ExecutionEngineException NullReferenceException etc.

Additional context

An example of rendering with WriteableBitmap in Avalonia: https://github.com/AvaloniaUI/Avalonia/blob/68a626f678b7fa4b1d1497cf7f419f7aebf703ee/samples/RenderDemo/Pages/WriteableBitmapPage.cs#L41
https://github.com/stevemonaco/AvaloniaDemos/tree/master/RealTimeBitmapAdapter
How to create Bitmap fron IntPtr
How to create a Bitmap from an image RGB buffer
AvaloniaUI/Avalonia#17365 (comment)

@dlemstra
Copy link
Owner

Marking this issue as an enhancement and hoping that someone will pick this up.

It looks like you will need to call Lock() on the WriteableBitmap and then write bytes to that memory address. You probably also need to check if RowBytes has padding per row. If you happen to get this working then please come back here with the solution.

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

No branches or pull requests

2 participants