SharpDx将位图保存到文件 [英] SharpDx Save Bitmap to File

查看:296
本文介绍了SharpDx将位图保存到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从渲染目标获得了Sharpdx Direct2D1位图。我想将其保存为图像文件。这是出于测试目的。我不确定是否需要WIC位图或如何转换这些位图。或者首先是如何接收WIC位图。

I have a Sharpdx Direct2D1 Bitmap from the render target. I want to save it to a file as an image though. This is for test purposes. I am not sure if i need a WIC bitmap for that or how to convert these bitmaps. Or how to receive the WIC bitmap in the first place.

我也找不到一个简单的解释来说明如何将该位图保存到文件中。

Also i can't find an easy explanation how to save this bitmap to a file in general.

任何有帮助的人。

编辑:

我现在正在使用这种方法: http://www.rolandk.de/wp/2013/06/inhalt-der-rendertarget-textur-in-ein-bitmap-kopieren/

I'm using this approach now: http://www.rolandk.de/wp/2013/06/inhalt-der-rendertarget-textur-in-ein-bitmap-kopieren/

这是德语,但是他说的是,您必须将
渲染目标的资源复制到暂存资源以通过cpu进行访问。然后将内容复制到位图。

It is in German, but what he says is, that you have to copy the resource of the render target to a staging resource to have access via the cpu. Then copy the contents over to a bitmap.

我正在尝试这种方法,然后最终使用bitmap.Save(filename)。但是以某种方式位图保持为空。也许我想念正确编码文件。但似乎更像是我根本没有从后台缓冲区目标中获取数据。

I'm trying this approach then finally using bitmap.Save(filename). But somehow the bitmap stays empty. Maybe i miss to encode the file correctly. But seems more like I don't get the data from the back buffer target at all.

推荐答案

问题由Dan回答Bysröm,如果您有wicBitmap,然后简单地将数据复制到gdi位图。

The question is answered by Dan Bysröm, if you have the wicBitmap and then simply copy the data to the gdi bitmap.

我通过编辑部分中发布的链接解决了我的特殊问题。我没有使用wic或任何东西,因为首先这可能是完全错误的方法。

I solved my particular problem with the link I posted in the edit part though. I did not use wic or anything, because that maybe was a totally wrong approach for my problem in the first place.

在编辑部分出现的问题已由不是使用CopyResource(...),而是使用CopySubResource(...),而是使用默认参数来全部复制。我不确定为什么CopyResource(...)不能正常工作。

The question that arised in the edit part was solved by not using CopyResource(...) but CopySubResource(...) instead with default parameter to copy all. I am not sure why CopyResource(...) did not work though.

这篇关于SharpDx将位图保存到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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