當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。