0

我有一个 Windows 应用商店应用程序和一个创建 SurfaceImageSource(direct3d 渲染)的运行时组件 (Cpp/CX)。

该应用程序显示图像的网格视图。当用户单击图像时,我想将其用作 RT 库中的纹理。我的选择是什么,什么是最好的。我应该将图像的路径传递给 RT Lib 并以某种方式将其加载到那里,还是应该将其加载到 CLR 中并将数据作为指针传递?

4

1 回答 1

0

Passing the filename might crash due to the security restrictions of Windows Store Apps. You can open a file only with a file picker or if you have been granted the explicit permission.

So when loading the file, you should save its content. E.g. to a byte array. Here is how the byte array can be generated from a StorageFile:

//file is the input StorageFile
var sourceStream = await file.OpenReadAsync();
//do anything else with the file, e.g. creating a BitmapImage
using(MemoryStream mem = new MemoryStream())
{
    //Reset the file stream
    sourceStream.Seek(0);
    sourceStream.AsStreamForRead().CopyTo(mem);
    var bytes = mem.ToArray();
}

Then you should pass the byte data to the DirectX library and load it to a texture. Alternatively you can use the BitmapDecoder class to convert the file to raw image data. The methods CreateAsync, GetPixelDataAsync and DetachPixelData might be of help.

于 2013-02-10T15:32:47.647 回答