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


C# Pixel.GetUpperBound方法代码示例

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


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

示例1: PixelsAsBitmap

        /*
         * This is an unsafe method call that locks the bitmap data
         * and uses low-level pointers to perform the updates. This
         * provides a crucial performance boost, and is generally
         * the suggested method for doing large image updates.
         */
        unsafe private Bitmap PixelsAsBitmap(Pixel[,] image)
        {
            int width = image.GetUpperBound(0)+1;
            int height = image.GetUpperBound(1)+1;

            // 24 bits per pixel Bitmap (8 bytes per color - R,G,B)
            Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);
            BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, bmp.PixelFormat);

            // Point to the beginning of our bitmap
            byte* origin = (byte*) bmpData.Scan0;

            // why not parallelize this too!
            Parallel.For(0, width,
            (xPixel) =>
            {
                for (int yPixel = 0; yPixel < height; yPixel++)
                {
                    // this probably looks very strange. But, think of it this way,
                    // we generally work with images that are 2-dimensional arrays
                    // where we can access a pixel by image[x,y], however, we are only
                    // using one pointer to access every byte, so we have to translate.
                    // Rows have image width * 3 bytes in them, so each row is spaced (width *3)
                    // bytes apart, therefore, to access a certain row (or y) we add
                    // (yPixel * width * 3) to the origin, and then access the column (or x)
                    // by adding (xPixel * 3).
                    byte* pixel = origin + (yPixel * width * 3) + (xPixel * 3);
                    pixel[0] = image[xPixel, yPixel].r;
                    pixel[1] = image[xPixel, yPixel].g;
                    pixel[2] = image[xPixel, yPixel].b;
                }
            });

            bmp.UnlockBits(bmpData);

            return bmp;
        }
开发者ID:BrutalSimplicity,项目名称:Blogs,代码行数:43,代码来源:Form1.cs


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