首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >透明透明RenderTarget

透明透明RenderTarget
EN

Stack Overflow用户
提问于 2016-07-20 15:21:23
回答 1查看 1.1K关注 0票数 1

我正在尝试使用SharpDX.Direct2D和WicBitmap作为渲染目标来绘制位图。

我的代码如下所示:

代码语言:javascript
复制
var wicFactory = new ImagingFactory();
var d2dFactory = new SharpDX.Direct2D1.Factory();

var wicBitmap = new SharpDX.WIC.Bitmap(wicFactory, width, height, 
    SharpDX.WIC.PixelFormat.Format32bppBGR, BitmapCreateCacheOption.CacheOnLoad);
var renderTargetProperties = new RenderTargetProperties(RenderTargetType.Default, 
    new SharpDX.Direct2D1.PixelFormat(Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Unknown), 
    0, 0, RenderTargetUsage.None, FeatureLevel.Level_DEFAULT);

var d2dRenderTarget = new WicRenderTarget(d2dFactory, wicBitmap, renderTargetProperties);

PathGeometry path = new PathGeometry(d2dFactory);
// Create the path figures here ...

SolidColorBrush brush = new SolidColorBrush(d2dRenderTarget, new RawColor4(1, 0, 0, 1));
d2dRenderTarget.BeginDraw();
// The problem is with this line
d2dRenderTarget.Clear(new RawColor4(1, 1, 1, 0));
d2dRenderTarget.DrawGeometry(path, brush, lineWidth);
d2dRenderTarget.EndDraw();

brush.Dispose();

path.Dispose();

bl = wicBitmap.Lock(BitmapLockFlags.Read);
// imageData is a byte[]
Marshal.Copy(bl.Data.DataPointer, imageData, 0, imageData.Length);
bl.Dispose();

d2dRenderTarget.Dispose();
wicBitmap.Dispose();
d2dFactory.Dispose();
wicFactory.Dispose();

File.WriteAllBytes("image.raw", imageData);

我想要创造的是一个背景透明的图像。如果AlphaMode中的PixelFormat未知或忽略,Clear方法将忽略透明颜色的alpha通道。如果我试图将AlphaMode设置为直或预乘,那么WicRenderTarget构造函数就会失败,出现COM错误:参数不正确。

什么是正确的参数组合,使alpha通道在Clear方法中不被忽略?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-22 11:30:10

您已经使用不支持alpha通道的WicBitmap SharpDX.WIC.PixelFormat.Format32bppBGR创建了您的SharpDX.WIC.PixelFormat.Format32bppBGR。请使用Format32bppPBGRA或类似的,并将alpha模式设置为Pre相乘,它应该可以工作。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38484552

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档