本文整理汇总了C#中ComputeCommandQueue.ReadFromImage方法的典型用法代码示例。如果您正苦于以下问题:C# ComputeCommandQueue.ReadFromImage方法的具体用法?C# ComputeCommandQueue.ReadFromImage怎么用?C# ComputeCommandQueue.ReadFromImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ComputeCommandQueue
的用法示例。
在下文中一共展示了ComputeCommandQueue.ReadFromImage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public static void Run(TextWriter log, ComputeContext context)
{
StartTest(log, "Image test");
try
{
log.Write("Creating command queue... ");
ComputeCommandQueue commands = new ComputeCommandQueue(context, context.Devices[0], ComputeCommandQueueFlags.None);
log.WriteLine("done.");
int width = 16;
int height = 16;
log.Write("Creating first bitmap and drawing shapes... ");
Bitmap firstBitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
Graphics graphics = Graphics.FromImage(firstBitmap);
graphics.FillEllipse(Brushes.Red, 0, 0, width / 2, height / 2);
graphics.FillRectangle(Brushes.Green, width / 2 + 1, 0, width / 2, height / 2);
graphics.FillRectangle(Brushes.Blue, width / 2 + 1, height / 2 + 1, width / 2, height / 2);
log.WriteLine("done.");
log.Write("Creating OpenCL image object from first bitmap... ");
ComputeImage2D clImage = new ComputeImage2D(context, ComputeMemoryFlags.ReadWrite | ComputeMemoryFlags.CopyHostPointer, firstBitmap);
log.WriteLine("done.");
log.Write("Creating second bitmap... ");
Bitmap secondBitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
BitmapData bmpData = secondBitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, secondBitmap.PixelFormat);
log.WriteLine("done.");
log.Write("Reading from OpenCL image object... ");
commands.ReadFromImage(clImage, bmpData.Scan0, true, null);
log.WriteLine("done.");
secondBitmap.UnlockBits(bmpData);
log.Write("Comparing bitmaps... ");
for (int i = 0; i < width; i++)
for (int j = 0; j < height; j++)
if (firstBitmap.GetPixel(i, j) != secondBitmap.GetPixel(i, j))
throw new Exception("Image data mismatch!");
log.WriteLine("passed.");
}
catch (Exception e)
{
log.WriteLine(e.ToString());
}
EndTest(log, "Image test");
}