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

PhotoSauce on Blazor WebAssembly not Supported #81

Open
Miguefie opened this issue Jan 6, 2022 · 3 comments
Open

PhotoSauce on Blazor WebAssembly not Supported #81

Miguefie opened this issue Jan 6, 2022 · 3 comments

Comments

@Miguefie
Copy link

Miguefie commented Jan 6, 2022

Im trying to use your PhotoSauce to resize a image loaded on Memory stream, is it possible to make it supported on Blazor?

Code that Im using:
var memoryStream = new MemoryStream(bytes, true);
var settings = new ProcessImageSettings { Width = Width , Height = Height };
var outStream = new FileStream(file.Name, FileMode.OpenOrCreate, FileAccess.ReadWrite);
MagicImageProcessor.ProcessImage(memoryStream, outStream, settings);

I Get this error:
The type initializer for 'PhotoSauce.Interop.Wic.IStreamImpl' threw an exception.
---> System.PlatformNotSupportedException: Operation is not supported on this platform.
at System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(Type type, Int32 size)
at PhotoSauce.Interop.Wic.IStreamImpl.createVtbl()
at PhotoSauce.Interop.Wic.IStreamImpl..cctor()

@saucecontrol
Copy link
Owner

Yeah, that error would be expected for WASM -- for now. Currently, we require access to the Windows native codecs to decode and encode images . Almost all of the remaining pipeline is pure managed code and should work in WASM, but in the current release, it would be a challenge to integrate.

The upcoming release will add support for pluggable codecs. That might include the standard set of xplat codecs (libjpeg, libpng, etc) compiled with emscipten, or managed codecs such as the ones from ImageSharp, which are implemented in pure C#. WASM is a lower priority at the moment than Linux, but both will be supported out of the box eventually.

@Webreaper
Copy link

It's worth noting that since Blazor now supports native assembly loading in Wasm, this might work. See the Sqlite demos that load the unmanaged DLL directly into the browser.

@saucecontrol
Copy link
Owner

I haven't had any time to look at this, but now that I have the base set of native codec packages done, it may not be too difficult to get them working in Wasm. vcpkg has a community-maintained triplet for Emscripten (https://github.com/microsoft/vcpkg/blob/master/triplets/community/wasm32-emscripten.cmake), and if anyone can get the codecs to reliably build with that, I could package them.

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

3 participants