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


C# FastBitmap.GetInitialPixelForRow方法代码示例

本文整理汇总了C#中FastBitmap.GetInitialPixelForRow方法的典型用法代码示例。如果您正苦于以下问题:C# FastBitmap.GetInitialPixelForRow方法的具体用法?C# FastBitmap.GetInitialPixelForRow怎么用?C# FastBitmap.GetInitialPixelForRow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FastBitmap的用法示例。


在下文中一共展示了FastBitmap.GetInitialPixelForRow方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BlendImages

        internal unsafe static Bitmap BlendImages(Bitmap start, Bitmap end, double blend, bool parallel, out TimeSpan time)
        {
            // Validate parameters
            if (start.Width != end.Width || start.Height != end.Height) 
                throw new ArgumentException("The sizes of images do not match.");
            if (blend < 0 || blend > 1) 
                throw new ArgumentOutOfRangeException("blend", blend, "Must be in the range [0.0,1.1].");

            // Create the output image
            int width = start.Width, height = start.Height;
            Bitmap output = new Bitmap(width, height);
            var sw = new Stopwatch();

            // Blend the input images into the output
            using (FastBitmap fastOut = new FastBitmap(output))
            using (FastBitmap fastStart = new FastBitmap(start))
            using (FastBitmap fastEnd = new FastBitmap(end))
            {
                if (parallel)
                {
                    // Blend the images in parallel
                    sw.Restart();
                    Parallel.For(0, height, j =>
                    {
                        PixelData* outPixel = fastOut.GetInitialPixelForRow(j);
                        PixelData* startPixel = fastStart.GetInitialPixelForRow(j);
                        PixelData* endPixel = fastEnd.GetInitialPixelForRow(j);

                        for (int i = 0; i < width; i++)
                        {
                            // Blend the input pixels into the output pixel
                            outPixel->R = (byte)((startPixel->R * blend) + .5 + (endPixel->R * (1 - blend))); // .5 for rounding
                            outPixel->G = (byte)((startPixel->G * blend) + .5 + (endPixel->G * (1 - blend)));
                            outPixel->B = (byte)((startPixel->B * blend) + .5 + (endPixel->B * (1 - blend)));

                            outPixel++;
                            startPixel++;
                            endPixel++;
                        }
                    });
                    sw.Stop();
                }
                else
                {
                    // Blend the images sequentially
                    sw.Restart();
                    for(int j=0; j<height; j++)
                    {
                        PixelData* outPixel = fastOut.GetInitialPixelForRow(j);
                        PixelData* startPixel = fastStart.GetInitialPixelForRow(j);
                        PixelData* endPixel = fastEnd.GetInitialPixelForRow(j);

                        for (int i = 0; i < width; i++)
                        {
                            // Blend the input pixels into the output pixel
                            outPixel->R = (byte)((startPixel->R * blend) + .5 + (endPixel->R * (1 - blend))); // .5 for rounding
                            outPixel->G = (byte)((startPixel->G * blend) + .5 + (endPixel->G * (1 - blend)));
                            outPixel->B = (byte)((startPixel->B * blend) + .5 + (endPixel->B * (1 - blend)));

                            outPixel++;
                            startPixel++;
                            endPixel++;
                        }
                    }
                    sw.Stop();
                }
            }

            // Return the new image
            time = sw.Elapsed;
            return output;
        }
开发者ID:Farouq,项目名称:semclone,代码行数:72,代码来源:MainForm.cs


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