本文整理汇总了C#中Bitmap.Lock方法的典型用法代码示例。如果您正苦于以下问题:C# Bitmap.Lock方法的具体用法?C# Bitmap.Lock怎么用?C# Bitmap.Lock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bitmap
的用法示例。
在下文中一共展示了Bitmap.Lock方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: colorFrameReader_FrameArrived
void colorFrameReader_FrameArrived(object sender, ColorFrameArrivedEventArgs e)
{
var colorFrame = e.FrameReference.AcquireFrame();
if (colorFrame != null)
{
using (colorFrame)
{
lastColorGain = colorFrame.ColorCameraSettings.Gain;
lastColorExposureTimeTicks = colorFrame.ColorCameraSettings.ExposureTime.Ticks;
if (yuvFrameReady.Count > 0)
{
lock (yuvByteBuffer)
colorFrame.CopyRawFrameDataToArray(yuvByteBuffer);
lock (yuvFrameReady)
foreach (var autoResetEvent in yuvFrameReady)
autoResetEvent.Set();
}
if ((rgbFrameReady.Count > 0) || (jpegFrameReady.Count > 0))
{
lock (rgbByteBuffer)
colorFrame.CopyConvertedFrameDataToArray(rgbByteBuffer, ColorImageFormat.Bgra);
lock (rgbFrameReady)
foreach (var autoResetEvent in rgbFrameReady)
autoResetEvent.Set();
}
if (jpegFrameReady.Count > 0)
{
// should be put in a separate thread?
stopWatch.Restart();
var bitmapSource = new Bitmap(imagingFactory, Kinect2Calibration.colorImageWidth, Kinect2Calibration.colorImageHeight, SharpDX.WIC.PixelFormat.Format32bppBGR, BitmapCreateCacheOption.CacheOnLoad);
var bitmapLock = bitmapSource.Lock(BitmapLockFlags.Write);
Marshal.Copy(rgbByteBuffer, 0, bitmapLock.Data.DataPointer, Kinect2Calibration.colorImageWidth * Kinect2Calibration.colorImageHeight * 4);
bitmapLock.Dispose();
var memoryStream = new MemoryStream();
//var fileStream = new FileStream("test" + frame++ + ".jpg", FileMode.Create);
//var stream = new WICStream(imagingFactory, "test" + frame++ + ".jpg", SharpDX.IO.NativeFileAccess.Write);
var stream = new WICStream(imagingFactory, memoryStream);
var jpegBitmapEncoder = new JpegBitmapEncoder(imagingFactory);
jpegBitmapEncoder.Initialize(stream);
var bitmapFrameEncode = new BitmapFrameEncode(jpegBitmapEncoder);
bitmapFrameEncode.Options.ImageQuality = 0.5f;
bitmapFrameEncode.Initialize();
bitmapFrameEncode.SetSize(Kinect2Calibration.colorImageWidth, Kinect2Calibration.colorImageHeight);
var pixelFormatGuid = PixelFormat.FormatDontCare;
bitmapFrameEncode.SetPixelFormat(ref pixelFormatGuid);
bitmapFrameEncode.WriteSource(bitmapSource);
bitmapFrameEncode.Commit();
jpegBitmapEncoder.Commit();
//fileStream.Close();
//fileStream.Dispose();
//Console.WriteLine(stopWatch.ElapsedMilliseconds + "ms " + memoryStream.Length + " bytes");
lock (jpegByteBuffer)
{
nJpegBytes = (int)memoryStream.Length;
memoryStream.Seek(0, SeekOrigin.Begin);
memoryStream.Read(jpegByteBuffer, 0, nJpegBytes);
}
lock (jpegFrameReady)
foreach (var autoResetEvent in jpegFrameReady)
autoResetEvent.Set();
//var file = new FileStream("test" + frame++ + ".jpg", FileMode.Create);
//file.Write(jpegByteBuffer, 0, nJpegBytes);
//file.Close();
bitmapSource.Dispose();
memoryStream.Close();
memoryStream.Dispose();
stream.Dispose();
jpegBitmapEncoder.Dispose();
bitmapFrameEncode.Dispose();
}
}
}
}