コード例 #1
0
ファイル: ViewColors.cs プロジェクト: fariz1992/Windows-API
        private unsafe void DrawColorRange()
        {
            HSV        hSV        = new HSV(0.0, 1.0, 1.0);
            BitmapData bitmapData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, bmp.PixelFormat);
            int        num        = Image.GetPixelFormatSize(bmp.PixelFormat) / 8;
            int        height     = bitmapData.Height;
            int        num2       = bitmapData.Width * num;
            byte *     ptr        = (byte *)(void *)bitmapData.Scan0;

            for (int i = 0; i < height; i++)
            {
                byte *ptr2 = ptr + i * bitmapData.Stride;
                for (int j = 0; j < num2; j += num)
                {
                    hSV.SetHue((double)(j / num));
                    Color color = hSV.ToRGB();
                    ptr2[j]     = color.B;
                    ptr2[j + 1] = color.G;
                    ptr2[j + 2] = color.R;
                }
            }
            bmp.UnlockBits(bitmapData);
        }
コード例 #2
0
        /// <summary>
        /// Draws all degrees of hue to the bitmap.
        /// </summary>
        private void DrawColorRange()
        {
            HSV   colorHSV = new HSV(0, 1, 1);
            Color colorRGB;

            unsafe
            {
                BitmapData bitmapData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, bmp.PixelFormat);

                int   bytesPerPixel  = System.Drawing.Bitmap.GetPixelFormatSize(bmp.PixelFormat) / 8;
                int   heightInPixels = bitmapData.Height;
                int   widthInBytes   = bitmapData.Width * bytesPerPixel;
                byte *PtrFirstPixel  = (byte *)bitmapData.Scan0;

                for (int y = 0; y < heightInPixels; y++)
                {
                    byte *currentLine = PtrFirstPixel + (y * bitmapData.Stride);
                    for (int x = 0; x < widthInBytes; x = x + bytesPerPixel)
                    {
                        //int oldBlue = currentLine[x];
                        //int oldGreen = currentLine[x + 1];
                        //int oldRed = currentLine[x + 2];

                        colorHSV.SetHue(x / bytesPerPixel);
                        //colorHSV.SetValue(y/360.0);
                        //colorHSV.SetSaturation(y / 360.0);
                        colorRGB = colorHSV.ToRGB();

                        currentLine[x]     = (byte)colorRGB.B;
                        currentLine[x + 1] = (byte)colorRGB.G;
                        currentLine[x + 2] = (byte)colorRGB.R;
                    }
                }
                bmp.UnlockBits(bitmapData);
            }
        }