从流加载 DDS 文件并在 WPF 应用程序中显示? [英] Load DDS file from stream and display in WPF application?

查看:28
本文介绍了从流加载 DDS 文件并在 WPF 应用程序中显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试加载 DirectDraw Surface (DDS) 文件并将其显示在 WPF 应用程序中.这是我从 zip 存档中获取流的方式:

using (ZipArchive clientArchive = ZipFile.OpenRead(levelsPath + mapName + @"\client.zip")){var entry = clientArchive.GetEntry("hud/minimap/ingamemap.dds");var stream = entry.Open();}

现在,如何在我的 WPF 应用程序中显示 DDS 图像(只是第一个最高质量的 mipmap)?

解决方案

我最近使用了来自 -控制.基于内存中的位图创建位图源这个答案为我指出了正确的方法.

I am trying to load a DirectDraw Surface (DDS) file and display it in a WPF application. This is how I get the stream from a zip archive:

using (ZipArchive clientArchive = ZipFile.OpenRead(levelsPath + mapName + @"\client.zip"))
{
    var entry = clientArchive.GetEntry("hud/minimap/ingamemap.dds");
    var stream = entry.Open();
}

Now, how do I display the DDS image (just the first, highest quality mipmap) in my WPF application?

解决方案

I recently used DDSImage class from kprojects. It can load DXT1 and DXT5 compressend DDS files.

Simply create a new instance with a byte array and access all mipmaps through the property images of type Bitmap[]:

DDSImage img = new DDSImage(File.ReadAllBytes(@"e:\myfile.dds"));

for (int i = 0; i < img.images.Length; i++)
{
    img.images[i].Save(@"e:\mipmap-" + i + ".png", ImageFormat.Png);
} 

Im you got your mipmap as Bitmap you could display it with an Image-Control. To create an BitmapSource, based on the Bitmap in memory this answer pointed me the right way.

这篇关于从流加载 DDS 文件并在 WPF 应用程序中显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆