本文整理汇总了C#中Bgr.Lock方法的典型用法代码示例。如果您正苦于以下问题:C# Bgr.Lock方法的具体用法?C# Bgr.Lock怎么用?C# Bgr.Lock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bgr
的用法示例。
在下文中一共展示了Bgr.Lock方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
var img = new Bgr<byte>[480, 640];
//***********************************************************************************************************************************************************************
Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("********* TColor[,] <=> Image<> conversions (built-in) ****************"); Console.ResetColor();
//to Image<>
Image<Bgr<byte>> lockedImg = img.Lock();
//from Image<>
var arr = lockedImg.Clone();
//***********************************************************************************************************************************************************************
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("********* Image<,> <=> OpenCV conversions (built-in) ****************"); Console.ResetColor();
//to IplImage
IplImage iplImage;
using (var uImg = img.Lock())
{
iplImage = uImg.AsOpenCvImage(); //data is shared
}
//from IplImage
var imgFromIpl = iplImage.AsImage();
//***********************************************************************************************************************************************************************
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("*********** Image<,> <=> Bitmap conversions (BitmapInterop) ****************"); Console.ResetColor();
//to Bitmap
var bmp = img.ToBitmap();
//from Bitmap
var imgFromBmp = bmp.ToArray();
}
示例2: SetImage
/// <summary>
/// Sets the specified image.
/// </summary>
/// <param name="image">Image to display.</param>
public void SetImage(Bgr<byte>[,] image)
{
if (bmp == null || bmp.Width != image.Width() || bmp.Height != image.Height())
{
bmp = new Bitmap(image.Width(), image.Height(), PixelFormat.Format24bppRgb);
}
BitmapData bmpData = bmp.Lock();
if (bmpData.BytesPerPixel != image.ColorInfo().Size)
{
bmpData.Dispose();
bmpData = null;
bmp = new Bitmap(image.Width(), image.Height(), PixelFormat.Format24bppRgb);
}
bmpData = bmpData ?? bmp.Lock();
using (var uIm = image.Lock())
{
Copy.UnsafeCopy2D(uIm.ImageData, bmpData.Data, uIm.Stride, bmpData.ScanWidth, uIm.Height);
}
bmpData.Dispose();
imageView.Image = bmp;
if (ScaleForm)
ClientSize = new Size(image.Width(), image.Height());
}
示例3: Main
static void Main(string[] args)
{
var img = new Bgr<byte>[480, 640];
//***********************************************************************************************************************************************************************
Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("********* TColor[,] <=> Image<> conversions (built-in) ****************"); Console.ResetColor();
//to Image<>
Image<Bgr<byte>> lockedImg = img.Lock();
//from Image<>
var arr = lockedImg.Clone();
//***********************************************************************************************************************************************************************
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("********* Image<,> <=> OpenCV conversions (built-in) ****************"); Console.ResetColor();
//to IplImage
IplImage iplImage;
using (var uImg = img.Lock())
{
iplImage = uImg.AsCvIplImage(); //data is shared
}
//from IplImage
var imgFromIpl = iplImage.AsImage();
//***********************************************************************************************************************************************************************
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("*********** Image<,> <=> Bitmap conversions (BitmapInterop) ****************"); Console.ResetColor();
//to Bitmap
var bmp = img.ToBitmap();
//from Bitmap
var imgFromBmp = bmp.ToArray();
//***********************************************************************************************************************************************************************
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("*********** Image<,> <=> BitmapSource conversions (BitmapSourceInterop) ****************"); Console.ResetColor();
//to generic-image
var colorBitmap = new BitmapImage(new Uri("http://www.online-image-editor.com//styles/2014/images/example_image.png"));
Bgra<byte>[,] colorImg = colorBitmap.ToArray<Bgra<byte>>();
//to BitmapSource
Gray<byte>[,] grayImg = img.ToGray();
BitmapSource grayBitmap = grayImg.ToBitmapSource();
}
示例4: SetImage
/// <summary>
/// Sets the specified image.
/// </summary>
/// <param name="image">Image to display.</param>
public void SetImage(Bgr<byte>[,] image)
{
if (bmp == null || bmp.Width != image.Width() || bmp.Height != image.Height())
{
bmp = new Bitmap(image.Width(), image.Height(), PixelFormat.Format24bppRgb);
}
using (BitmapData bmpData = bmp.Lock())
using (var uIm = image.Lock())
{
Copy.UnsafeCopy2D(uIm.ImageData, bmpData.Data, uIm.Stride, bmpData.ScanWidth, uIm.Height);
}
PictureBox.Image = bmp;
if (ScaleForm)
ClientSize = new Size(image.Width(), image.Height());
}