本文整理汇总了C#中Bitmap.ConvertFrom方法的典型用法代码示例。如果您正苦于以下问题:C# Bitmap.ConvertFrom方法的具体用法?C# Bitmap.ConvertFrom怎么用?C# Bitmap.ConvertFrom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bitmap
的用法示例。
在下文中一共展示了Bitmap.ConvertFrom方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CS_W_ZX_DetectCode
public async Task CS_W_ZX_DetectCode(string filename, BarcodeFormat barcodeFormat, string barcodeValue)
{
// Load a bitmap in Bgra8 colorspace
var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Input/" + filename));
var source = new StorageFileImageSource(file);
Bitmap bitmapBgra8 = await source.GetBitmapAsync(null, OutputOption.PreserveAspectRatio);
Assert.AreEqual(ColorMode.Bgra8888, bitmapBgra8.ColorMode);
// Convert the bitmap to Nv12 colorspace (colorspace used when decoding barcode from cameras)
var bitmapYuv = new Bitmap(bitmapBgra8.Dimensions, ColorMode.Yuv420Sp);
bitmapYuv.ConvertFrom(bitmapBgra8);
// Decode the barcode
var reader = new BarcodeReader
{
Options = new DecodingOptions
{
PossibleFormats = new BarcodeFormat[] { barcodeFormat },
TryHarder = true
}
};
Result resultBgra8 = reader.Decode(
bitmapBgra8.Buffers[0].Buffer.ToArray(),
(int)bitmapBgra8.Dimensions.Width,
(int)bitmapBgra8.Dimensions.Height,
BitmapFormat.BGRA32
);
Result resultYuv = reader.Decode(
bitmapYuv.Buffers[0].Buffer.ToArray(),
(int)bitmapYuv.Buffers[0].Pitch, // Should be width here but I haven't found a way to pass both width and stride to ZXing yet
(int)bitmapYuv.Dimensions.Height,
BitmapFormat.Gray8
);
Assert.IsNotNull(resultBgra8, "Decoding barcode in Bgra8 colorspace failed");
Assert.AreEqual(barcodeValue, resultBgra8.Text);
Assert.IsNotNull(resultYuv, "Decoding barcode in Nv12 colorspace failed");
Assert.AreEqual(barcodeValue, resultYuv.Text);
}