问题描述
嗨,我是 c# 开发新手,我在 Visual Studio 中使用 https://www.nuget.org/packages/Imazen.WebP 和 c# 和 winforms,我成功地将 .webp 图像加载到图片框中,而且我已经有了使用 Image 翻转图片的代码.RotateFlip(RotateFlipType) 方法,但现在我想知道如何将 .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 图像,如果有人可以查看并提供反馈,那就太好了
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 (将#修改为@)