本文整理汇总了C#中CanvasDevice.IsPixelFormatSupported方法的典型用法代码示例。如果您正苦于以下问题:C# CanvasDevice.IsPixelFormatSupported方法的具体用法?C# CanvasDevice.IsPixelFormatSupported怎么用?C# CanvasDevice.IsPixelFormatSupported使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CanvasDevice
的用法示例。
在下文中一共展示了CanvasDevice.IsPixelFormatSupported方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestBitmapPixelFormats
public void TestBitmapPixelFormats()
{
var device = new CanvasDevice();
foreach (var format in AllPixelFormats())
{
// Unknown formats should not be supported.
if (!formatFlags.ContainsKey(format))
{
Assert.IsFalse(device.IsPixelFormatSupported(format));
ValidateCannotCreateBitmap(device, format, FirstSupportedAlphaMode(format));
continue;
}
// Optional formats may be legitimately not supported, depending on the device.
if (!device.IsPixelFormatSupported(format))
{
Assert.IsTrue((formatFlags[format] & FormatFlags.Optional) != 0);
ValidateCannotCreateBitmap(device, format, FirstSupportedAlphaMode(format));
continue;
}
// We should be able to create this format using all its supported alpha modes.
var lotsOfZeroes = new byte[1024];
foreach (var alphaMode in SupportedAlphaModes(format))
{
CanvasBitmap.CreateFromBytes(device, lotsOfZeroes, 4, 4, format, 96, alphaMode);
}
// Other alpha modes should not be supported.
foreach (var alphaMode in UnsupportedAlphaModes(format))
{
ValidateCannotCreateBitmap(device, format, alphaMode);
}
// We should also be able to create this format without explicitly specifying an alpha mode.
var bitmap = CanvasBitmap.CreateFromBytes(device, lotsOfZeroes, 4, 4, format);
Assert.AreEqual(FirstSupportedAlphaMode(format), bitmap.AlphaMode);
// Some formats can be drawn directly, while others cannot.
if ((formatFlags[format] & FormatFlags.CannotDraw) == 0)
{
ValidateCanDrawImage(device, bitmap);
}
else
{
ValidateCannotDrawImage(device, bitmap);
}
// But all formats should be drawable when used as effect inputs.
ValidateCanDrawImage(device, new ColorMatrixEffect { Source = bitmap });
}
}
示例2: TestBitmapPixelFormats
public void TestBitmapPixelFormats()
{
using (new DisableDebugLayer())
{
var device = new CanvasDevice();
foreach (var format in AllPixelFormats())
{
// Unknown formats should not be supported.
if (!formatFlags.ContainsKey(format))
{
Assert.IsFalse(device.IsPixelFormatSupported(format));
ValidateCannotCreateBitmap(device, format, FirstSupportedAlphaMode(format));
continue;
}
// Optional formats may be legitimately not supported, depending on the device.
if (!device.IsPixelFormatSupported(format))
{
Assert.IsTrue((formatFlags[format] & FormatFlags.Optional) != 0);
ValidateCannotCreateBitmap(device, format, FirstSupportedAlphaMode(format));
continue;
}
// We should be able to create this format using all its supported alpha modes.
var lotsOfZeroes = new byte[1024];
foreach (var alphaMode in SupportedAlphaModes(format))
{
CanvasBitmap.CreateFromBytes(device, lotsOfZeroes, 4, 4, format, 96, alphaMode);
}
// Other alpha modes should not be supported.
foreach (var alphaMode in UnsupportedAlphaModes(format))
{
ValidateCannotCreateBitmap(device, format, alphaMode);
}
// We should also be able to create this format without explicitly specifying an alpha mode.
var bitmap = CanvasBitmap.CreateFromBytes(device, lotsOfZeroes, 4, 4, format);
Assert.AreEqual(FirstSupportedAlphaMode(format), bitmap.AlphaMode);
// Some formats can be drawn directly, while others cannot.
if ((formatFlags[format] & FormatFlags.CannotDraw) == 0)
{
ValidateCanDrawImage(device, bitmap);
}
else
{
ValidateCannotDrawImage(device, bitmap);
}
// But all formats should be drawable when used as effect inputs.
ValidateCanDrawImage(device, new ColorMatrixEffect { Source = bitmap });
// Make sure we can get and set pixels of this format.
var bytes = bitmap.GetPixelBytes();
Assert.IsTrue(bytes.All(b => b == 0));
var sequence = Enumerable.Range(0, bytes.Length)
.Select(value => (byte)value)
.ToArray();
bitmap.SetPixelBytes(sequence);
var otherBytes = bitmap.GetPixelBytes();
CollectionAssert.AreEqual(sequence, otherBytes);
}
}
}
示例3: TestRenderTargetPixelFormats
public void TestRenderTargetPixelFormats()
{
using (new DisableDebugLayer())
{
var device = new CanvasDevice();
foreach (var format in AllPixelFormats())
{
// Unknown formats should not be supported.
if (!formatFlags.ContainsKey(format))
{
ValidateCannotCreateRenderTarget(device, format, FirstSupportedAlphaMode(format));
continue;
}
// Non-renderable formats should also not be supported.
if ((formatFlags[format] & FormatFlags.RenderTarget) == 0)
{
ValidateCannotCreateRenderTarget(device, format, FirstSupportedAlphaMode(format));
continue;
}
// Validate implementation assumption: all rendertarget formats also support premultiplied
// alpha. If D2D ever adds support for a rendertarget format where this is not the case,
// CanvasRenderTargetFactory::CreateFromDirect3D11Surface should be updated to know about
// that, along the same lines as how CanvasBitmap::CreateFromDirect3D11Surface already has
// smarts to choose a suitable alpha mode depending on the pixel format.
Assert.IsTrue((formatFlags[format] & FormatFlags.PremultipliedAlpha) != 0);
// Optional formats may be legitimately not supported, depending on the device.
if (!device.IsPixelFormatSupported(format))
{
Assert.IsTrue((formatFlags[format] & FormatFlags.Optional) != 0);
ValidateCannotCreateRenderTarget(device, format, FirstSupportedAlphaMode(format));
continue;
}
// We should be able to create and render to this format using all its supported alpha modes.
foreach (var alphaMode in SupportedAlphaModes(format))
{
var renderTarget = new CanvasRenderTarget(device, 16, 16, 96, format, alphaMode);
ValidateCanDrawToRenderTarget(renderTarget);
}
// Other alpha modes should not be supported.
foreach (var alphaMode in UnsupportedAlphaModes(format))
{
ValidateCannotCreateRenderTarget(device, format, alphaMode);
}
}
}
}