1

我使用 SharpDX,但PixelFormat. 我想做它A8_UNorm并使用一个,OpacityMask但我得到一个UnsupportedPixelFormatException. 但根据 MSDN,一切都应该没问题。代码:

     PixelFormat PF = new PixelFormat(Format.A8_UNorm, AlphaMode.Straight);  
     var desc = new Texture2DDescription()
            {
                Width = Width,
                Height = Height,
                Format = Format.A8_UNorm,
                SampleDescription = new SampleDescription(1, 0),
                ArraySize = 1,
                CpuAccessFlags = 0,
                Usage = ResourceUsage.Default,
                MipLevels = 1,
                BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
            };

            using (var d = new DataStream(desc.Width * desc.Height, true, true))
            {
                for (var i = 0; i < desc.Width * desc.Height / 4; i++) d.Write(0);
                using (Texture2D tex = new Texture2D(GameControl.Device, desc, new DataRectangle(d.DataPointer, desc.Width)))
                {
                    using (Surface temp = tex.QueryInterface<Surface>())
                    {
                        Target = new RenderTarget(Factory2D, temp, new RenderTargetProperties(PF));
                        OpacityMask = new Bitmap(Target, temp, new BitmapProperties(PF)); //Exception is here
                    }
                }
            }
4

1 回答 1

1

像素格式支持取决于软件和硬件。您可以检查您的平台是否支持您想要的CheckFormatSupport()。我这样使用它:

var format = Format.A8_UNorm;
var supportRequired = FormatSupport.RenderTarget;
var isSupported = device.CheckFormatSupport(format).HasFlag(supportRequired);

请注意,除了 之外还有许多选项FormatSupport.RenderTarget,因此请测试您尝试使用的所有选项。

于 2013-05-01T12:56:11.110 回答