问题描述
我之前通过发布 this 问题解决了 webp 问题。但是,avif 扩展名仍未解决。
我想在 wpf 图像控件中使用 BitmapImage 显示 this avif 扩展的图像。
但是BitmapImage不支持avif扩展,不显示。
那怎么才能显示avif的图片呢?
以下是我目前使用的代码。
private static BitmapImage LoadImage(byte[] imageData,string ext) {
if (imageData == null || imageData.Length == 0) return null;
var image = new BitmapImage();
using(var mem = new MemoryStream(imageData)) {
mem.Position = 0;
image.BeginInit();
image.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
image.CacheOption = BitmapCacheOption.OnLoad;
image.UriSource = null;
if (ext == "webp") {
SimpleDecoder dec = new SimpleDecoder();
dec.DecodeFromBytes(imageData,imageData.Length).Save(mem,System.Drawing.Imaging.ImageFormat.Png);
image.StreamSource = mem;
} else if (ext == "avif") {
//Todo: display avif format image
}
else {
image.StreamSource = mem;
}
image.EndInit();
}
image.Freeze();
return image;
}
using(WebClient wc = new WebClient()) {
Byte[] Mydata = wc.DownloadData("http://www.imageview.kro.kr/images/test.avif");
//The address in this code is a temporary created address,//but the actual address requires a header request. So I use WebClient.
Console.WriteLine(Mydata.Length);
wc.dispose();
dispatcher.Invoke(dispatcherPriority.normal,new Action(delegate {
thumbnail.source = LoadImage(Mydata,"avif");
}));
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)