旋转图片框后将 .webp 保存为 .webp 图像 c# imazen.webp

问题描述

嗨,我是 c# 开发新手,我在 Visual Studio 中使用 https://www.nuget.org/packages/Imazen.WebP 和 c# 和 winforms,我成功地将 .webp 图像加载到图片框中,而且我已经有了使用 Image 翻转图片代码.RotateFlip(RotateFlipType) 方法,但现在我想知道如何将 .webp 图像再次保存为 .webp 图像但进行修改(翻转)。

这是我在图片框中加载 webp 的代码

Bitmap bmp;

if (ext == ".webp")
{
    var webpDecoder = new SimpleDecoder();

    using (Stream inputStream = File.Open(nameImagen,FileMode.Open))
    {
        byte[] buffer = new byte[16 * 1024];
        
        using (MemoryStream ms = new MemoryStream())
        {
            int read;
            
            while ((read = inputStream.Read(buffer,buffer.Length)) > 0)
            {
                 ms.Write(buffer,read);
            }

            var bytes = ms.ToArray();
            bmp = webpDecoder.DecodeFromBytes(bytes,bytes.LongLength);
        }
}/* finish webp conversion */

pictureBox1.Image = bmp;

这是翻转我的图片框的功能

private void flipHImagen(object senders,EventArgs e)
{
    pictureBox1.Image.RotateFlip(RotateFlipType.RotateNoneFlipX);
    pictureBox1.Invalidate();
}

private void flipVImagen(object senders,EventArgs e)
{
    pictureBox1.Image.RotateFlip(RotateFlipType.RotateNoneFlipY);
    pictureBox1.Invalidate();
}

一切正常,但现在我想知道,如何使用翻转修改和相同的图像格式 .webp 保存我的 .webp 图像?

这是我目前使用常规图像(如 jpg、png)保存功能代码


private void savePictureBox(object senders,EventArgs e)
{
    SaveFileDialog dialog = new SaveFileDialog();

    if (dialog.ShowDialog() == DialogResult.OK)
    {
        int width = Convert.ToInt32(drawImage.Width);
        int height = Convert.ToInt32(drawImage.Height);
        Bitmap bmp = new Bitmap(width,height);
        drawImage.DrawToBitmap(bmp,new Rectangle(0,width,height);
        bmp.Save(dialog.FileName,ImageFormat.Tiff);
    }
}

更新:

我有这个代码,它似乎可以完成保存 webp 图像的工作,使用静态 webp 图像,如果有人可以查看并提供反馈,那就太好了

Source

if (dialog.ShowDialog() == DialogResult.OK)
{
    string extension = System.IO.Path.GetExtension(dialog.FileName);

    if (extension == ".webp")
    {
        var webpFileName = dialog.FileName;

        using (Bitmap bitmap = new Bitmap(pictureBox1.Image))
        {
            using (var saveimagestream = System.IO.File.Open(webpFileName,FileMode.Create))
            {
                 var encoder = new SimpleEncoder();
                 encoder.Encode(bitmap,saveimagestream,-1);
            }
        }
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...