当前位置: 首页>>代码示例>>C#>>正文


C# ComputeCommandQueue.ReadFromImage方法代码示例

本文整理汇总了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");
        }
开发者ID:kwaegel,项目名称:Cloox2,代码行数:50,代码来源:ImageTest.cs


注:本文中的ComputeCommandQueue.ReadFromImage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。