Пример #1
0
        /// <summary>
        /// Returns an image with the Hue modified by the specified ammount
        /// </summary>
        /// <param name="image"></param>
        /// <param name="h"></param>
        /// <returns></returns>
        public static Bitmap ChangeHue(Bitmap image, float h)
        {
            bool IsTransparent = false;

            try
            {
                //Set up progress
                Global.bTackPixelProgress    = true;
                Global.iCurrentOp_PixelCount = 0;
                Global.iCurrentOp_PixelTotal = image.Width * image.Height;

                UnsafeBitmap newUBMP = new UnsafeBitmap(image);
                newUBMP.LockImage();

                Color cColor;
                for (int iWidth = 0; iWidth < image.Width; iWidth++)
                {
                    for (int iHeight = 0; iHeight < image.Height; iHeight++)
                    {
                        cColor = newUBMP.GetPixel(iWidth, iHeight);
                        HLS newHLS = new HLS();
                        newHLS.Red   = cColor.R;
                        newHLS.Blue  = cColor.B;
                        newHLS.Green = cColor.G;

                        newHLS.Hue += h;
                        newHLS.ToRGB();

                        if (!IsTransparent)
                        {
                            IsTransparent = Global.CheckPixelTransparency(cColor);
                        }

                        cColor = Color.FromArgb(newHLS.Red, newHLS.Green, newHLS.Blue);
                        newUBMP.SetPixel(iWidth, iHeight, cColor);

                        Global.iCurrentOp_PixelCount++;
                    }
                }

                newUBMP.UnlockImage();

                Global.bTackPixelProgress = false;
            }
            catch (Exception ex)
            {
                Global.WriteToLog(ex);
            }
            if (IsTransparent)
            {
                image.MakeTransparent();
            }
            return(image);
        }
Пример #2
0
        /// <summary>
        /// Returns the source image with the luminosity modified by the specified ammount
        /// </summary>
        /// <param name="sourceimage"></param>
        /// <param name="l"></param>
        /// <returns></returns>
        public static Bitmap ChangeLuminosity(Bitmap image, float l)
        {
            bool IsTransparent = false;

            try
            {
                //Set up progress
                Global.bTackPixelProgress    = true;
                Global.iCurrentOp_PixelCount = 0;
                Global.iCurrentOp_PixelTotal = image.Width * image.Height;

                UnsafeBitmap newUBMP = new UnsafeBitmap(image);
                newUBMP.LockImage();

                Color c;
                for (int iWidth = 0; iWidth < image.Width; iWidth++)
                {
                    for (int iHeight = 0; iHeight < image.Height; iHeight++)
                    {
                        c = newUBMP.GetPixel(iWidth, iHeight);
                        HLS newHLS = new HLS();
                        newHLS.Red   = c.R;
                        newHLS.Blue  = c.B;
                        newHLS.Green = c.G;

                        if (newHLS.Luminance + l >= 1f)
                        {
                            newHLS.Luminance = 1f;
                        }
                        else if (newHLS.Luminance + l <= 0.0f)
                        {
                            newHLS.Luminance = 0.0f;
                        }
                        else
                        {
                            newHLS.Luminance += l;
                        }
                        newHLS.ToRGB();

                        if (!IsTransparent)
                        {
                            IsTransparent = Global.CheckPixelTransparency(c);
                        }

                        c = Color.FromArgb(newHLS.Red, newHLS.Green, newHLS.Blue);
                        newUBMP.SetPixel(iWidth, iHeight, c);

                        Global.iCurrentOp_PixelCount++;
                    }
                }

                newUBMP.UnlockImage();

                Global.bTackPixelProgress = false;
            }
            catch (Exception ex)
            {
                Global.WriteToLog(ex);
            }
            if (IsTransparent)
            {
                image.MakeTransparent();
            }

            return(image);
        }