Click here to Skip to main content
15,664,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Is possible store webp file to FileStream or memorystream ?

installed web-wrapper from nuget

What I have tried:

using WebPWrapper;

Image imgPhoto = null;

if (Path.GetExtension(pathFileName) == ".webp")
    //FileStream stream = new FileStream(pathFileName, FileMode.Open, FileAccess.Read);
    //imgPhoto = Image.FromStream(stream);
    //pictureBox.Image = imgPhoto;
    WebP webp = new WebP();
    pictureBox.Image = webp.Load(pathFileName);
    FileStream stream = new FileStream(pathFileName, FileMode.Open, FileAccess.Read);
    imgPhoto = Image.FromStream(stream);
    pictureBox.Image = imgPhoto;

//other, convert webp file to byte[]

WebP webp = new WebP();                        
string pathFileName = openFileDialog.FileName;
byte[] rawWebp = File.ReadAllBytes(pathFileName);
webp.GetInfo(rawWebp, out width, out height, out has_alpha, out has_animation, out format);

//rawWebp not null
//error to create ms
MemoryStream ms = new MemoryStream(rawWebp);
Updated 30-Aug-22 3:49am

1 solution

Assuming you mean this library:
GitHub - JosePineiro/WebP-wrapper: Wrapper for libwebp in C#. The most complete wapper in pure managed C#. Exposes Simple Decoding API, Simple Encoding API, Advanced Encoding API (with stadistis of compresion), Get version library and WebPGetFeatures[^]

The documentation shows method to read (decode) from and write (encode) to byte arrays.

There doesn't seem to be any specific mention of using streams. If the library doesn't support it, you would need to log a feature request[^] with the developer.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900