我正在使用C#,需要处理Jpeg-XR图像。然而,这些图像是以base64字符串的形式呈现的,需要直接转换为位图对象。我可以将其写入文件并进行转换,但这会极大地影响我的运行时间。
我想知道是否有人能帮我做一个示例代码,或者一个提示?(我已经试过了Magick.Net,但这对我没有用,而且似乎也无法直接加载JXR映像)。
非常感谢
发布于 2017-06-14 04:45:25
JPEG XR以前称为HD和。
您可以在WPF库中使用System.Windows.Media.Imaging中的类System.Windows.Media.Imaging来操作.jxr图像。
该类为编码图像定义一个解码器。以下代码将JXR文件转换为Bmp文件:
using System.IO;
using System.Windows.Media.Imaging;
public class JXrLib
{
public static void JxrToBmp(string source, string target)
{
Stream imageStreamSource = new FileStream(source, FileMode.Open, FileAccess.Read, FileShare.Read);
WmpBitmapDecoder decoder = new WmpBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapSource bitmapSource = decoder.Frames[0];
var encoder = new BmpBitmapEncoder(); ;
encoder.Frames.Add(BitmapFrame.Create(bitmapSource));
using (var stream = new FileStream(target, FileMode.Create))
{
encoder.Save(stream);
}
}
}代码经过测试并运行良好。
备选方案2:
如果您对使用Magick.Net感兴趣,可以在https://jxrlib.codeplex.com中使用jxrlib库。
将文件JXRDecApp.exe和JXREncApp.exe复制到bin目录中,并从磁盘上具有.jxr扩展名的文件中读取。(您必须使用visual studio编译jxrlib )
代码示例:
// Read first frame of jxr image
//JXRDecApp.exe ,JXREncApp.exe should be located in the path of binaries
using (MagickImage image = new MagickImage(@"images\myimage1.jxr"))
{
// Save frame as bmp
image.Write("myimage2.bmp");
// even , Save frame as jxr
image.Write("myimage2.jxr");
}https://stackoverflow.com/questions/44530763
复制相似问题