コード例 #1
0
        private static Bitmap MakeGrayscale(Bitmap original)
        {
            //create a blank bitmap the same size as original
            Bitmap newBitmap = new Bitmap(original.Width, original.Height);
            //get a graphics object from the new image
            Graphics g = Graphics.FromImage(newBitmap);

            //create the grayscale ColorMatrix
            System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(
                new float[][]
            {
                new float[] { .3f, .3f, .3f, 0, 0 },
                new float[] { .59f, .59f, .59f, 0, 0 },
                new float[] { .11f, .11f, .11f, 0, 0 },
                new float[] { 0, 0, 0, 1, 0 },
                new float[] { 0, 0, 0, 0, 1 }
            });
            //create some image attributes
            System.Drawing.Imaging.ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes();
            //set the color matrix attribute
            attributes.SetColorMatrix(colorMatrix);
            //draw the original image on the new image
            //using the grayscale color matrix
            g.DrawImage(original, new Rectangle(0, 0, original.Width, original.Height), 0, 0, original.Width, original.Height, GraphicsUnit.Pixel, attributes);
            //dispose the Graphics object
            g.Dispose();
            return(newBitmap);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: dan-runs/DevelopOCR
        private static string MakeImageBlackNWhite(string image_path, float threshold)
        {
            Bitmap SourceImage = new Bitmap(image_path);

            using (Graphics gr = Graphics.FromImage(SourceImage)) // SourceImage is a Bitmap object
            {
                var gray_matrix = new float[][] {
                    new float[] { 0.299f, 0.299f, 0.299f, 0, 0 },
                    new float[] { 0.587f, 0.587f, 0.587f, 0, 0 },
                    new float[] { 0.114f, 0.114f, 0.114f, 0, 0 },
                    new float[] { 0, 0, 0, 1, 0 },
                    new float[] { 0, 0, 0, 0, 1 }
                };

                var ia = new System.Drawing.Imaging.ImageAttributes();
                ia.SetColorMatrix(new System.Drawing.Imaging.ColorMatrix(gray_matrix));
                ia.SetThreshold(threshold); // Change this threshold as needed
                var rc = new Rectangle(0, 0, SourceImage.Width, SourceImage.Height);
                gr.DrawImage(SourceImage, rc, 0, 0, SourceImage.Width, SourceImage.Height, GraphicsUnit.Pixel, ia);
            }
            string bw_path = "C:/Users/Bruce Huffa/source/repos/DevelopOCR/DevelopOCR/test_bw.png";

            SourceImage.Save(bw_path);
            return(bw_path);
        }
コード例 #3
0
        private void TransParentBackGroundImage(float alpha)
        {
            Bitmap   bitmap = new Bitmap(Definition.DISPLAY_WIDTH, Definition.DISPLAY_HEIGHT);
            Graphics g      = Graphics.FromImage(bitmap);

            //ColorMatrixで透明度を設定
            System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix();
            colorMatrix.Matrix00 = 1;     //Red
            colorMatrix.Matrix11 = 1;     //Green
            colorMatrix.Matrix22 = 1;     //Blue
            colorMatrix.Matrix33 = alpha; //Alpha
            colorMatrix.Matrix44 = 1;     //常に1
            //
            System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes();
            //ColorMatrixを設定する
            imageAttributes.SetColorMatrix(colorMatrix);
            //何故かDraw
            g.DrawImage(m_definition.Image_Battle,
                        new Rectangle(0, 0, m_definition.Image_Battle.Width, m_definition.Image_Battle.Height),
                        0, 0, m_definition.Image_Battle.Width, m_definition.Image_Battle.Height,
                        GraphicsUnit.Pixel, imageAttributes);
            //m_definition.Image_Battle.Dispose();
            g.Dispose();
            //バトルコントロール背景に画像を適用
            Battle_pictureBox.BackgroundImage = bitmap;
        }
コード例 #4
0
        public static Bitmap AplyColor(Color color, Bitmap Img)
        {
            float R = color.R / 255.0f;
            float G = color.G / 255.0f;
            float B = color.B / 255.0f;

            float[][] Values =
            {
                new float[] { R *3.0f,        0,        0, 0, 0 },
                new float[] {       0, G * 3.0f,        0, 0, 0 },
                new float[] {       0,        0, B * 3.0f, 0, 0 },
                new float[] {       0,        0,        0, 1, 0 },
                new float[] {       0,        0,        0, 0, 1 }
            };
            System.Drawing.Imaging.ColorMatrix     Matrix = new System.Drawing.Imaging.ColorMatrix(Values);
            System.Drawing.Imaging.ImageAttributes IA     = new System.Drawing.Imaging.ImageAttributes();
            IA.SetColorMatrix(Matrix);
            Bitmap Effect = (Bitmap)Img.Clone();

            using (Graphics g = Graphics.FromImage(Effect))
            {
                g.DrawImage(Img, new Rectangle(0, 0, Effect.Width, Effect.Height), 0, 0, Effect.Width, Effect.Height, GraphicsUnit.Pixel, IA);
            }
            Img = Effect;
            return(Img);
        }
コード例 #5
0
ファイル: Helpers.cs プロジェクト: olehgerus/Watermarking
        /// <summary>
        /// Set brightness for the image
        /// </summary>
        /// <param name="image">input bitmap</param>
        /// <param name="value">value from -255 to 255</param>
        /// <returns></returns>
        public static Bitmap SetBrightness(Bitmap image, int value)
        {
            var tempBitmap  = image;
            var finalValue  = value / 255.0f;
            var newBitmap   = new Bitmap(tempBitmap.Width, tempBitmap.Height);
            var newGraphics = Graphics.FromImage(newBitmap);

            float[][] floatColorMatrix =
            {
                new float[] {          1,          0,          0, 0, 0 },
                new float[] {          0,          1,          0, 0, 0 },
                new float[] {          0,          0,          1, 0, 0 },
                new float[] {          0,          0,          0, 1, 0 },
                new[]       { finalValue, finalValue, finalValue, 1, 1 }
            };

            var newColorMatrix = new System.Drawing.Imaging.ColorMatrix(floatColorMatrix);
            var attributes     = new System.Drawing.Imaging.ImageAttributes();

            attributes.SetColorMatrix(newColorMatrix);
            newGraphics.DrawImage(tempBitmap, new System.Drawing.Rectangle(0, 0, tempBitmap.Width, tempBitmap.Height), 0, 0, tempBitmap.Width, tempBitmap.Height, System.Drawing.GraphicsUnit.Pixel, attributes);
            attributes.Dispose();
            newGraphics.Dispose();
            return(newBitmap);
        }
コード例 #6
0
ファイル: ImageEx.cs プロジェクト: KennethYap/MonoGame
        internal static Image RGBToBGR(this Image bmp)
        {
            Image newBmp;
            if ((bmp.PixelFormat & Imaging.PixelFormat.Indexed) != 0)
            {
                newBmp = new Bitmap(bmp.Width, bmp.Height, Imaging.PixelFormat.Format32bppArgb);
            }
            else
            {
                newBmp = bmp;
            }
        
            try
            {
                System.Drawing.Imaging.ImageAttributes ia = new System.Drawing.Imaging.ImageAttributes();
                System.Drawing.Imaging.ColorMatrix cm = new System.Drawing.Imaging.ColorMatrix(rgbtobgr);

                ia.SetColorMatrix(cm);
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newBmp))
                {
                    g.DrawImage(bmp, new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, bmp.Width, bmp.Height, System.Drawing.GraphicsUnit.Pixel, ia);
                }
            }
            finally
            {
                if (newBmp != bmp)
                {
                    bmp.Dispose();
                }
            }
            
            return newBmp;
        }
コード例 #7
0
        //this function is not entirely from me:
        public Bitmap AdjustBrightnessMatrix(Bitmap img, float RedMul, float GreenMul, float BlueMul)
        {
            //if (value == 0) { return img; } // No change, so just return

            //System.Drawing.Imaging.ColorMap cmm = new System.Drawing.Imaging.ColorMap();



            //float sb = (float)value / 255F;
            //float d = 1f / sb;
            float[][] colorMatrixElements =
            {
                new float[] { RedMul,        0,       0, 0, 0 }, //new float[] {1,  0,  0,  0, 0},
                new float[] {      0, GreenMul,       0, 0, 0 }, //new float[] {0,  1,  0,  0, 0},
                new float[] {      0,        0, BlueMul, 0, 0 }, //new float[] {0,  0,  1,  0, 0},
                new float[] {      0,        0,       0, 1, 0 }, //new float[] {0,  0,  0,  1, 0},
                new float[] {      0,        0,       0, 1, 0 }  //new float[] {sb, sb, sb, 1, 1}
            };

            System.Drawing.Imaging.ColorMatrix     cm      = new System.Drawing.Imaging.ColorMatrix(colorMatrixElements);
            System.Drawing.Imaging.ImageAttributes imgattr = new System.Drawing.Imaging.ImageAttributes();
            System.Drawing.Rectangle rc = new System.Drawing.Rectangle(0, 0, img.Width, img.Height);
            System.Drawing.Graphics  g  = System.Drawing.Graphics.FromImage(img);
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
            imgattr.SetColorMatrix(cm);
            g.DrawImage(img, rc, 0, 0, img.Width, img.Height, System.Drawing.GraphicsUnit.Pixel, imgattr);

            imgattr.Dispose();
            g.Dispose();
            return(img);
        }
コード例 #8
0
        public Image OverlayImage(Image baseImage, Image topImage, float transparency)
        {
            System.Drawing.Imaging.ImageAttributes ia = new System.Drawing.Imaging.ImageAttributes();
            System.Drawing.Imaging.ColorMatrix     cm = new System.Drawing.Imaging.ColorMatrix();
            cm.Matrix33 = transparency;
            ia.SetColorMatrix(cm);
            Graphics g = null;

            try
            {
                g = Graphics.FromImage(baseImage);
                Rectangle rect = new Rectangle((int)(topImage.Width * 0.1), (int)(topImage.Height * 0.2), (int)(topImage.Width * 0.8), (int)(topImage.Height * 0.6));
                // YOU MAY DEFINE THE RECT AS THIS AS WELL
                //Rectangle rect = new Rectangle(0, 0, baseImage.Width,      baseImage.Height, baseImage.Width);
                g.DrawImage(topImage, rect, 0, 0, topImage.Width, topImage.Height, GraphicsUnit.Pixel, ia);
                return(baseImage);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                g.Dispose();
                topImage.Dispose();
            }
        }
コード例 #9
0
        public static Image CreateGrayscaleImage(Image img)
        {
            //グレースケールの描画先となるImageオブジェクトを作成
            Bitmap newImg = new Bitmap(img.Width, img.Height);
            //newImgのGraphicsオブジェクトを取得
            Graphics g = Graphics.FromImage(newImg);

            //ColorMatrixオブジェクトの作成
            //グレースケールに変換するための行列を指定する
            System.Drawing.Imaging.ColorMatrix cm =
                new System.Drawing.Imaging.ColorMatrix(
                    new float[][] {
                new float[] { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f },
                new float[] { 0.0f, 1.0f, 0.0f, 0.0f, 0.0f },
                new float[] { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f },
                new float[] { 0.0f, 0.0f, 0.0f, 0.5f, 0.0f },
                new float[] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }
            });
            //ImageAttributesオブジェクトの作成
            System.Drawing.Imaging.ImageAttributes ia =
                new System.Drawing.Imaging.ImageAttributes();
            //ColorMatrixを設定する
            ia.SetColorMatrix(cm);

            //ImageAttributesを使用してグレースケールを描画
            g.DrawImage(img,
                        new Rectangle(0, 0, img.Width, img.Height),
                        0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);

            //リソースを解放する
            g.Dispose();

            return(newImg);
        }
コード例 #10
0
        internal static Image RGBToBGR(this Image bmp)
        {
            Image newBmp;

            if ((bmp.PixelFormat & Imaging.PixelFormat.Indexed) != 0)
            {
                newBmp = new Bitmap(bmp.Width, bmp.Height, Imaging.PixelFormat.Format32bppArgb);
            }
            else
            {
                newBmp = bmp;
            }

            try
            {
                System.Drawing.Imaging.ImageAttributes ia = new System.Drawing.Imaging.ImageAttributes();
                System.Drawing.Imaging.ColorMatrix     cm = new System.Drawing.Imaging.ColorMatrix(rgbtobgr);

                ia.SetColorMatrix(cm);
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newBmp))
                {
                    g.Clear(Color.Transparent);
                    g.DrawImage(bmp, new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, bmp.Width, bmp.Height, System.Drawing.GraphicsUnit.Pixel, ia);
                }
            }
            finally
            {
                if (newBmp != bmp)
                {
                    bmp.Dispose();
                }
            }

            return(newBmp);
        }
コード例 #11
0
ファイル: FormCaptureSheet.cs プロジェクト: srrrkn/ScShoAlpha
        // 半透明にした画像を重ねる
        public void Add_currentImage(Image img)
        {
            // ImageオブジェクトのGraphicsオブジェクトを作成する
            Graphics g = Graphics.FromImage(DispScreenImg);

            System.Drawing.Imaging.ImageAttributes ia = new System.Drawing.Imaging.ImageAttributes();
            Rectangle rect = new Rectangle();

            rect.X      = 0;
            rect.Y      = 0;
            rect.Width  = DispScreenImg.Width;
            rect.Height = DispScreenImg.Height;
            // ColorMatrixオブジェクトの作成
            System.Drawing.Imaging.ColorMatrix cm = new System.Drawing.Imaging.ColorMatrix();
            // ColorMatrixの行列の値を変更して、アルファ値が0.5に変更されるようにする
            cm.Matrix00 = 1;
            cm.Matrix11 = 1;
            cm.Matrix22 = 1;
            cm.Matrix33 = 0.3F;
            cm.Matrix44 = 1;
            // ColorMatrixを設定する
            ia.SetColorMatrix(cm);

            // 画像を指定された位置、サイズで描画する
            g.DrawImage(img, rect, 0, 0, DispScreenImg.Width, DispScreenImg.Height, GraphicsUnit.Pixel, ia);
            // Imageオブジェクトのリソースを解放する
            img.Dispose();
            // Graphicsオブジェクトのリソースを解放する
            g.Dispose();
        }
コード例 #12
0
        private static System.Drawing.Bitmap ConvertHopsToMaltIcon(System.Drawing.Bitmap bmp)
        {
            var img = new System.Drawing.Bitmap(bmp.Width, bmp.Height, bmp.PixelFormat);

            using (var g = System.Drawing.Graphics.FromImage(img))
            {
                g.TranslateTransform(bmp.Width / 2, bmp.Height / 2);
                g.RotateTransform(180);
                g.ScaleTransform((bmp.Width - 6f) / bmp.Width, 1.0f);
                g.TranslateTransform(-bmp.Width / 2 + 3, -bmp.Height / 2);

                float[][] ptsArray =
                {
                    new float[] {    1,   0,   0,   0, 0 },
                    new float[] {    0,   1,   0,   0, 0 },
                    new float[] {    0,   0,   1,   0, 0 },
                    new float[] {    0,   0,   0,   1, 0 },
                    new float[] { .50f, .0F, .0f, .0f, 1 },
                };
                var clrMatrix  = new System.Drawing.Imaging.ColorMatrix(ptsArray);
                var imgAttribs = new System.Drawing.Imaging.ImageAttributes();
                imgAttribs.SetColorMatrix(clrMatrix,
                                          System.Drawing.Imaging.ColorMatrixFlag.Default,
                                          System.Drawing.Imaging.ColorAdjustType.Default);
                g.DrawImage(bmp,
                            new System.Drawing.Rectangle(0, 0, img.Width, img.Height),
                            0, 0, img.Width, img.Height,
                            System.Drawing.GraphicsUnit.Pixel, imgAttribs);
            }
            bmp.Dispose();
            return(img);
        }
コード例 #13
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Bitmap sourceImage = null;

            DA.GetData(0, ref sourceImage);

            double Value = 0;

            DA.GetData(1, ref Value);

            //create a Bitmap the size of the image provided
            Bitmap bmp = new Bitmap(sourceImage.Width, sourceImage.Height);

            //create a graphics object from the image
            Graphics gfx = Graphics.FromImage(bmp);

            //create a color matrix object
            System.Drawing.Imaging.ColorMatrix matrix = new System.Drawing.Imaging.ColorMatrix();


            //set the opacity
            matrix.Matrix33 = Convert.ToSingle(Value);

            //create image attributes
            System.Drawing.Imaging.ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes();

            //set the color(opacity) of the image
            attributes.SetColorMatrix(matrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap);

            //now draw the image
            gfx.DrawImage(sourceImage, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, sourceImage.Width, sourceImage.Height, GraphicsUnit.Pixel, attributes);

            DA.SetData(0, bmp);
        }
コード例 #14
0
ファイル: EffectPanel.cs プロジェクト: KHCmaster/PPD
        private void Draw(Graphics g, string filename, EffectStateStructure state)
        {
            if (state == null || state.Alpha <= 0 || state.ScaleX == 0 || state.ScaleY == 0)
            {
                return;
            }
            var   temp  = g.Transform.Clone();
            Image image = dict[filename];

            if (state.ScaleX * image.Width >= 1 && state.ScaleY * image.Height >= 1)
            {
                g.TranslateTransform(state.X, state.Y);
                g.RotateTransform(state.Rotation);
                g.ScaleTransform(state.ScaleX, state.ScaleY);
                g.TranslateTransform(-image.Width / 2, -image.Height / 2);
                var cm = new System.Drawing.Imaging.ColorMatrix
                {
                    Matrix00 = 1,
                    Matrix11 = 1,
                    Matrix22 = 1,
                    Matrix33 = state.Alpha,
                    Matrix44 = 1
                };
                var ia = new System.Drawing.Imaging.ImageAttributes();
                ia.SetColorMatrix(cm);
                g.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, ia);
            }
            g.Transform = temp;
        }
コード例 #15
0
ファイル: ImageEx.cs プロジェクト: Zodge/MonoGame
        internal static Image RGBToBGR(this Image bmp)
        {
            Image newBmp;
            if ((bmp.PixelFormat & Imaging.PixelFormat.Indexed) != 0)
            {
                newBmp = new Bitmap(bmp.Width, bmp.Height, Imaging.PixelFormat.Format32bppArgb);
            }
            else
            {
                // Need to clone so the call to Clear() below doesn't clear the source before trying to draw it to the target.
                newBmp = (Image)bmp.Clone();
            }

            try
            {
                System.Drawing.Imaging.ImageAttributes ia = new System.Drawing.Imaging.ImageAttributes();
                System.Drawing.Imaging.ColorMatrix cm = new System.Drawing.Imaging.ColorMatrix(rgbtobgr);

                ia.SetColorMatrix(cm);
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newBmp))
                {
                    g.Clear(Color.Transparent);
                    g.DrawImage(bmp, new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, bmp.Width, bmp.Height, System.Drawing.GraphicsUnit.Pixel, ia);
                }
            }
            finally
            {
                if (newBmp != bmp)
                {
                    bmp.Dispose();
                }
            }

            return newBmp;
        }
コード例 #16
0
ファイル: MainForm.cs プロジェクト: dziedrius/osd-gs
        public static Bitmap MakeGrayscale(Bitmap original)
        {
            using (var gr = Graphics.FromImage(original))
            {
                //var grayMatrix = new[]
                //                      {
                //                          new float[] { 0.299f, 0.299f, 0.299f, 0, 0 },
                //                          new float[] { 0.587f, 0.587f, 0.587f, 0, 0 },
                //                          new float[] { 0.114f, 0.114f, 0.114f, 0, 0 },
                //                          new float[] { 0, 0, 0, 1, 0 },
                //                          new float[] { 0, 0, 0, 0, 1 }
                //                      };

                var grayMatrix = new[]
                {
                    new float[] { 1.5f, 1.5f, 1.5f, 0, 0 },
                    new float[] { 1.5f, 1.5f, 1.5f, 0, 0 },
                    new float[] { 1.5f, 1.5f, 1.5f, 0, 0 },
                    new float[] { 0, 0, 0, 1, 0 },
                    new float[] { -1, -1, -1, 0, 1 }
                };

                var ia = new System.Drawing.Imaging.ImageAttributes();
                ia.SetColorMatrix(new System.Drawing.Imaging.ColorMatrix(grayMatrix));
                ia.SetThreshold(0.7f); // Change this threshold as needed
                var rc = new Rectangle(0, 0, original.Width, original.Height);
                gr.DrawImage(original, rc, 0, 0, original.Width, original.Height, GraphicsUnit.Pixel, ia);
            }

            return(original);
        }
コード例 #17
0
        public TintParameters(Color color)
            : base(color)
        {
            ImageAttributes = new System.Drawing.Imaging.ImageAttributes();

            float[][] ptsArray =
            {
                //new float[] {1, 0, 0, 0, 0},
                //new float[] {0, 1, 0, 0, 0},
                //new float[] {0, 0, 1, 0, 0},
                //new float[] { color.Value1 / 255f, color.Value2 / 255f, color.Value3 / 255f, color.Alpha / 255f, 0},
                //new float[] {0, 0, 0, 0, 1}
                new float[] { color.Value1 / 255f,                   0,                   0,                  0, 0 },
                new float[] {                   0, color.Value2 / 255f,                   0,                  0, 0 },
                new float[] {                   0,                   0, color.Value3 / 255f,                  0, 0 },
                new float[] {                   0,                   0,                   0, color.Alpha / 255f, 0 },
                new float[] {                   0,                   0,                   0,                  0, 1 }

                //inverse image
                //new float[] {-1, 0, 0, 0, 0},
                //new float[] {0, -1, 0, 0, 0},
                //new float[] {0, 0, -1, 0, 0},
                //new float[] {0, 0, 0, 1, 0},
                //new float[] {1, 1, 1, 0, 1}
            };

            ImageAttributes.SetColorMatrix(new System.Drawing.Imaging.ColorMatrix(ptsArray));
        }
コード例 #18
0
        /// <summary>
        ///	画像を半透明にして描画する
        /// </summary>
        /// <param name="imgImage">描画する画像</param>
        /// <param name="x">画像の左上端のX座標</param>
        /// <param name="y">画像の左上端のY座標</param>
        public void DrawImageTransparent(Image imgImage, int x, int y)
        {
            //アルファ値の変更
            System.Drawing.Imaging.ColorMatrix cm = new System.Drawing.Imaging.ColorMatrix();

            //ColorMatrixの行列の値を変更する
            cm.Matrix00 = 1;
            cm.Matrix11 = 1;
            cm.Matrix22 = 1;
            cm.Matrix33 = 0.5F;
            cm.Matrix44 = 1;

            //ImageAttributesオブジェクトの作成
            System.Drawing.Imaging.ImageAttributes ia = new System.Drawing.Imaging.ImageAttributes();
            ia.SetColorMatrix(cm);

            //画像を描画
            try{
//				pTarget.Graphics.DrawImage(imgImage,0,0,210,297,SCALE,ia);
                pTarget.Graphics.DrawImage(imgImage, new Rectangle(0, 0, imgImage.Width,
                                                                   imgImage.Height), x, y, imgImage.Width, imgImage.Height, SCALE, ia);
            }
            catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }
コード例 #19
0
 protected override void OnPaint(PaintEventArgs pe)
 {
     base.OnPaint(pe);
     ImageAttrs.SetColorMatrix(ColorMatrix);
     pe.Graphics.DrawImage(Face.Face, new Rectangle(0, 0, Face.Face.Width, Face.Face.Height),
                           0, 0, Face.Face.Width, Face.Face.Height, GraphicsUnit.Pixel, ImageAttrs);
 }
コード例 #20
0
        /// <summary>
        /// converts a bitmap image to grayscale
        /// </summary>
        /// <param name="source">bitmap source</param>
        /// <returns>returns a grayscaled bitmap</returns>
        public Bitmap ConvertToGrayscale(Bitmap source)
        {
            Bitmap bm = new Bitmap(source.Width, source.Height);

            float[][] matrix =
            {
                new   float[]   { 0.299f, 0.299f, 0.299f, 0, 0 },
                new   float[]   { 0.587f, 0.587f, 0.587f, 0, 0 },
                new   float[]   { 0.114f, 0.114f, 0.114f, 0, 0 },
                new   float[]   {      0,      0,      0, 1, 0 },
                new   float[]   {      0,      0,      0, 0, 1 }
            };
            System.Drawing.Imaging.ColorMatrix     cm   = new System.Drawing.Imaging.ColorMatrix(matrix);
            System.Drawing.Imaging.ImageAttributes attr = new System.Drawing.Imaging.ImageAttributes();
            attr.SetColorMatrix(cm);
            //Image tmp
            Graphics g = Graphics.FromImage(bm);

            try
            {
                Rectangle destRect = new Rectangle(0, 0, bm.Width, bm.Height);
                g.DrawImage(source, destRect, 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixel, attr);
            }
            finally
            {
                g.Dispose();
            }
            return(bm);
        }
コード例 #21
0
ファイル: MainForm.cs プロジェクト: dziedrius/osd-gs
        public static Bitmap MakeGrayscale(Bitmap original)
        {
            using (var gr = Graphics.FromImage(original))
            {
                //var grayMatrix = new[]
                //                      {
                //                          new float[] { 0.299f, 0.299f, 0.299f, 0, 0 },
                //                          new float[] { 0.587f, 0.587f, 0.587f, 0, 0 },
                //                          new float[] { 0.114f, 0.114f, 0.114f, 0, 0 },
                //                          new float[] { 0, 0, 0, 1, 0 },
                //                          new float[] { 0, 0, 0, 0, 1 }
                //                      };

                var grayMatrix = new[]
                                     {
                                         new float[] { 1.5f, 1.5f, 1.5f, 0, 0 },
                                         new float[] { 1.5f, 1.5f, 1.5f, 0, 0 },
                                         new float[] { 1.5f, 1.5f, 1.5f, 0, 0 },
                                         new float[] { 0, 0, 0, 1, 0 },
                                         new float[] { -1, -1, -1, 0, 1 }
                                     };

                var ia = new System.Drawing.Imaging.ImageAttributes();
                ia.SetColorMatrix(new System.Drawing.Imaging.ColorMatrix(grayMatrix));
                ia.SetThreshold(0.7f); // Change this threshold as needed
                var rc = new Rectangle(0, 0, original.Width, original.Height);
                gr.DrawImage(original, rc, 0, 0, original.Width, original.Height, GraphicsUnit.Pixel, ia);
            }

            return original;
        }
コード例 #22
0
        private void UpdateImage(System.Windows.Forms.PaintEventArgs e)
        {
            if (!Collected && "solid".Equals(Properties.Settings.Default.BackgroundMode) && SolidImage != null && !LaMulanaItemTrackerForm.DialogOpen)
            {
                e.Graphics.Clear(Properties.Settings.Default.BackgroundColor);
                System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes();
                System.Drawing.Imaging.ColorMatrix     colorMatrix     = new System.Drawing.Imaging.ColorMatrix(
                    new float[][] {
                    new float[] { 0, 0, 0, 0, 0 },
                    new float[] { 0, 0, 0, 0, 0 },
                    new float[] { 0, 0, 0, 0, 0 },
                    new float[] { 0, 0, 0, 1, 0 },
                    new float[] { Properties.Settings.Default.ItemColor.R / 255.0f,
                                  Properties.Settings.Default.ItemColor.G / 255.0f,
                                  Properties.Settings.Default.ItemColor.B / 255.0f,
                                  0, 1 }
                });

                imageAttributes.SetColorMatrix(colorMatrix);
                e.Graphics.DrawImage(SolidImage, new System.Drawing.Rectangle(0, 0, 40, 40), 0, 0, 40, 40, System.Drawing.GraphicsUnit.Pixel, imageAttributes);

                Image = null;
                if (ForeCollected && ForeImage != null)
                {
                    e.Graphics.DrawImage(ForeImage, new System.Drawing.Point(0, 0));
                }
            }
        }
コード例 #23
0
ファイル: Images_Ext.cs プロジェクト: kaizoman666/EffectTool
        public static Bitmap Invert(this Image source)
        {
            //create a blank bitmap the same size as original
            Bitmap newBitmap = new Bitmap(source.Width, source.Height);
            //get a graphics object from the new image
            Graphics g = Graphics.FromImage(newBitmap);

            // create the negative color matrix
            System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(new float[][]
            {
                new float[] { -1, 0, 0, 0, 0 },
                new float[] { 0, -1, 0, 0, 0 },
                new float[] { 0, 0, -1, 0, 0 },
                new float[] { 0, 0, 0, 1, 0 },
                new float[] { 1, 1, 1, 0, 1 }
            });

            // create some image attributes
            System.Drawing.Imaging.ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes();

            attributes.SetColorMatrix(colorMatrix);

            g.DrawImage(source, new Rectangle(0, 0, source.Width, source.Height),
                        0, 0, source.Width, source.Height, GraphicsUnit.Pixel, attributes);

            //dispose the Graphics object
            g.Dispose();

            return(newBitmap);
        }
コード例 #24
0
        public WalkInTheDark()
        {
            BackColor  = Color.Black;
            Lightimage = Image.FromFile("./Content/Light.png");

            float[][] colorMatrixElements =
            {
                new float[] { TransparentGameComponent.TransparancyKey.R / 255.0f,                                                   0,                                                   0, 0, 0 },
                new float[] {                                                   0, TransparentGameComponent.TransparancyKey.G / 255.0f,                                                   0, 0, 0 },
                new float[] {                                                   0,                                                   0, TransparentGameComponent.TransparancyKey.B / 255.0f, 0, 0 },
                new float[] {                                                   0,                                                   0,                                                   0, 1, 0 },
                new float[] {                                                   0,                                                   0,                                                   0, 0, 1 }
            };

            var cmPicture = new System.Drawing.Imaging.ColorMatrix(colorMatrixElements);

            // Set the new color matrix
            var iaPicture  = new System.Drawing.Imaging.ImageAttributes();
            var bmpPicture = new Bitmap(Lightimage.Width, Lightimage.Height);

            iaPicture.SetColorMatrix(cmPicture);
            // Set the Graphics object from the bitmap
            var gfxPicture = Graphics.FromImage(bmpPicture);
            // New rectangle for the picture, same size as the original picture
            var rctPicture = new Rectangle(0, 0, Lightimage.Width, Lightimage.Height);

            // Draw the new image
            gfxPicture.DrawImage(Lightimage, rctPicture, 0, 0, Lightimage.Width, Lightimage.Height, GraphicsUnit.Pixel, iaPicture);
            // Set the PictureBox to the new inverted colors bitmap
            Lightimage = bmpPicture;
        }
コード例 #25
0
        private void frmPlayerInfo_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.SmoothingMode     = SmoothingMode.AntiAlias;
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;

            System.Drawing.Imaging.ColorMatrix attrMatrix = new System.Drawing.Imaging.ColorMatrix();
            attrMatrix.Matrix33 = 0.5f;
            System.Drawing.Imaging.ImageAttributes attr = new System.Drawing.Imaging.ImageAttributes();
            attr.SetColorMatrix(attrMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap);


            if (_player == null)
            {
                Image raceSnapshot = Models.Matchup.SnapshotImageFromRace(Models.Matchup.Races.Random);
                e.Graphics.DrawImage(raceSnapshot, new Rectangle(0, 0, Width, Height), 0, 0, raceSnapshot.Width, raceSnapshot.Height, GraphicsUnit.Pixel, attr);

                e.Graphics.DrawString(string.Format("Custom Game Hero"), new Font("Arial", (float)(12 * Program.yScale), FontStyle.Regular, GraphicsUnit.Pixel), new SolidBrush(ColorTranslator.FromHtml("#47c5ff")), 20, 20);
            }
            else
            {
                Image raceSnapshot = Models.Matchup.SnapshotImageFromRace(_player.Race);
                e.Graphics.DrawImage(raceSnapshot, new Rectangle(0, 0, Width, Height), 0, 0, raceSnapshot.Width, raceSnapshot.Height, GraphicsUnit.Pixel, attr);

                Rectangle portrait       = DrawPortrait(e.Graphics, _player.Portrait, 0, 0, Program.xScale > 1 ? 1 : Program.xScale, Program.yScale > 1 ? 1 : Program.yScale);
                int       fontSize       = 24;
                int       availablespace = Width - (portrait.Width + 4);
                Font      font           = new Font("Arial", (float)((fontSize * 0.6) * Program.yScale), FontStyle.Bold, GraphicsUnit.Pixel);
                SizeF     size;
                while ((size = e.Graphics.MeasureString(_player.Name, font)).Width > availablespace)
                {
                    fontSize -= 1;
                    font      = new Font("Arial", (float)((fontSize * 0.6) * Program.yScale), FontStyle.Bold, GraphicsUnit.Pixel);
                }

                e.Graphics.DrawString(_player.Name, font, new SolidBrush(ColorTranslator.FromHtml("#47c5ff")), portrait.Width + 4, 12);

                int       verticalSpace = Height - portrait.Height;
                Rectangle icon          = DrawLeagueImage(e.Graphics, _player.League, _player.Place, 2, portrait.Width + 4, (int)(size.Height + 16 * Program.yScale), Program.xScale, Program.yScale);
                if (_player.Place > 0)
                {
                    e.Graphics.DrawString(string.Format("#{0}", _player.Place), new Font("Arial", icon.Height / 2, FontStyle.Regular, GraphicsUnit.Pixel), new SolidBrush(ColorTranslator.FromHtml("#47c5ff")), icon.Left + icon.Width + (int)(4 * Program.xScale), icon.Top + icon.Height - (icon.Height / 2) - 6);
                    if (_player.Points > -1)
                    {
                        e.Graphics.DrawString("P", new Font("Arial", icon.Height / 2, FontStyle.Bold, GraphicsUnit.Pixel), new SolidBrush(ColorTranslator.FromHtml("#47c5ff")), icon.Left + (icon.Width / 2), icon.Top + icon.Height);
                        e.Graphics.DrawString(string.Format("{0}", _player.Points), new Font("Arial", icon.Height / 2, FontStyle.Regular, GraphicsUnit.Pixel), new SolidBrush(ColorTranslator.FromHtml("#47c5ff")), icon.Left + icon.Width + (int)(4 * Program.xScale), icon.Top + icon.Height);

                        e.Graphics.DrawString("W", new Font("Arial", icon.Height / 2, FontStyle.Bold, GraphicsUnit.Pixel), new SolidBrush(ColorTranslator.FromHtml("#47c5ff")), icon.Left + (icon.Width / 2), icon.Top + icon.Height + (icon.Height / 2));
                        e.Graphics.DrawString(string.Format("{0}", _player.Wins), new Font("Arial", icon.Height / 2, FontStyle.Regular, GraphicsUnit.Pixel), new SolidBrush(ColorTranslator.FromHtml("#47c5ff")), icon.Left + icon.Width + (int)(4 * Program.xScale), icon.Top + icon.Height + (icon.Height / 2));

                        if (_player.Losses > -1)
                        {
                            e.Graphics.DrawString("L", new Font("Arial", icon.Height / 2, FontStyle.Bold, GraphicsUnit.Pixel), new SolidBrush(ColorTranslator.FromHtml("#47c5ff")), icon.Left + (icon.Width / 2), icon.Top + icon.Height + ((icon.Height / 2) * 2));
                            e.Graphics.DrawString(string.Format("{0}", _player.Losses), new Font("Arial", icon.Height / 2, FontStyle.Regular, GraphicsUnit.Pixel), new SolidBrush(ColorTranslator.FromHtml("#47c5ff")), icon.Left + icon.Width + (int)(4 * Program.xScale), icon.Top + icon.Height + ((icon.Height / 2) * 2));
                        }
                    }
                }
            }
        }
コード例 #26
0
        public static PictureBox NewImage()
        {
            Image originalImage = Image.FromFile(BackImagePath);

            ImageSize = originalImage;

            Bitmap tempImage = new Bitmap(originalImage.Width, originalImage.Height);
            Bitmap markImage = new Bitmap(100, 100);

            markImage.SetResolution(100, 100);
            Graphics g = Graphics.FromImage(markImage);

            g.PageUnit = GraphicsUnit.Point;
            g.Clear(Color.Empty);

            Font       font      = fontSet;
            SolidBrush drawBrush = new SolidBrush(fontColor);

            g.DrawString(MarkImageText, font, drawBrush, new RectangleF(0, 0, 100, 100), StringFormat.GenericDefault);

            float    setOpacity = MarkOpacity / 100;
            Graphics newGrp     = Graphics.FromImage(tempImage);

            float[][] setColorMatrix =
            {
                new float[] { 1, 0, 0,          0, 0 },
                new float[] { 0, 1, 0,          0, 0 },
                new float[] { 0, 0, 1,          0, 0 },
                new float[] { 0, 0, 0, setOpacity, 0 },
                new float[] { 0, 0, 0,          0, 1 },
            };
            System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(setColorMatrix);

            System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes();
            imageAttributes.SetColorMatrix(
                colorMatrix,
                System.Drawing.Imaging.ColorMatrixFlag.Default,
                System.Drawing.Imaging.ColorAdjustType.Bitmap
                );

            newGrp.DrawImage(originalImage, 0, 0, originalImage.Width, originalImage.Height);
            float orw = (float)(originalImage.Width * 0.3);
            float orh = (float)(originalImage.Height * 0.4);

            float mix = (originalImage.Width / 2) + (orw / 2);
            float miy = (originalImage.Height / 2) + (orh / 2) + ((orh / 2) / 2);

            float msw = markImage.Width;
            float msh = markImage.Height;

            newGrp.DrawImage(markImage, new Rectangle((int)mix, (int)miy, (int)orw, (int)orh), 0.0F, 0.0F, msw, msh, GraphicsUnit.Pixel, imageAttributes);
            PictureBox pictureBox = new PictureBox();

            pictureBox.Image = tempImage;

            return(pictureBox);
        }
コード例 #27
0
        public void PaintBackground(Graphics g, bool bOnWindow, float scale2)
        {
            if (null != this.Owner_MemoryApplication.Bitmap_Bg)
            {
                // ビットマップ画像の不透明度を指定します。
                System.Drawing.Imaging.ImageAttributes ia;
                {
                    System.Drawing.Imaging.ColorMatrix cm =
                        new System.Drawing.Imaging.ColorMatrix();
                    cm.Matrix00 = 1;
                    cm.Matrix11 = 1;
                    cm.Matrix22 = 1;
                    cm.Matrix33 = this.Owner_MemoryApplication.BgOpaque;//α値。0~1か?
                    cm.Matrix44 = 1;

                    //ImageAttributesオブジェクトの作成
                    ia = new System.Drawing.Imaging.ImageAttributes();
                    //ColorMatrixを設定する
                    ia.SetColorMatrix(cm);
                }
                float x = 0;
                float y = 0;
                if (bOnWindow)
                {
                    x += this.Owner_MemoryApplication.BgLocationScaled.X;
                    y += this.Owner_MemoryApplication.BgLocationScaled.Y;
                }
                float     width   = this.Owner_MemoryApplication.Bitmap_Bg.Width;
                float     height  = this.Owner_MemoryApplication.Bitmap_Bg.Height;
                Rectangle dstRect = new Rectangle((int)x, (int)y, (int)(scale2 * width), (int)(scale2 * height));

                if (!bOnWindow && this.Owner_MemoryApplication.BgOpaque < 1.0f)
                {
                    // ウィンドウの中に描画するのではない場合(書き出し時)に、
                    // 少しでも半透明になっているなら、背景色を白で塗りつぶします。

                    g.FillRectangle(
                        Brushes.White,
                        dstRect
                        );
                }

                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; //ドット絵のまま拡縮するように。しかし、この指定だと半ピクセル左上にずれるバグ。
                g.PixelOffsetMode   = System.Drawing.Drawing2D.PixelOffsetMode.Half;              //半ピクセル左上にずれるバグに対応。
                g.DrawImage(
                    this.Owner_MemoryApplication.Bitmap_Bg,
                    dstRect,
                    0,
                    0,
                    width,
                    height,
                    GraphicsUnit.Pixel,
                    ia
                    );
            }
        }
コード例 #28
0
ファイル: Form1.cs プロジェクト: SeiyaIwabuchi/CSharpClass
 public Form1()
 {
     InitializeComponent();
     bm1 = new Bitmap("../../tea.jpg");
     bm2 = new Bitmap("../../tea.jpg");
     pictureBox1.Image = bm1;
     ia.SetColorMatrix(cm);
     //bm1のGraphicsオブジェクトを取得
     g = Graphics.FromImage(bm2);
 }
コード例 #29
0
ファイル: Mark.cs プロジェクト: goodluck3586/CSharpClass2019
        public static PictureBox NewImage()
        {
            Image orgImg = Image.FromFile(BackImgPath);

            ImageSize = orgImg;
            Bitmap tmpImg  = new Bitmap(orgImg.Width, orgImg.Height);
            Bitmap markImg = new Bitmap(100, 100);

            markImg.SetResolution(100, 100);
            Graphics g = Graphics.FromImage(markImg);

            g.PageUnit = GraphicsUnit.Point;
            g.Clear(Color.Empty);
            Font       fn        = fnSet;
            SolidBrush drawBrush = new SolidBrush(fnCol);

            g.DrawString(MarkImgText, fn, drawBrush, new RectangleF(0, 0, 100, 100), StringFormat.GenericDefault);

            float setOpacity = MarkOpacity / 100;

            Graphics newGrp = Graphics.FromImage(tmpImg);

            float[][] setColrMartix =
            {
                new float [] { 1, 0, 0,          0, 0 },
                new float [] { 0, 1, 0,          0, 0 },
                new float [] { 0, 0, 1,          0, 0 },
                new float [] { 0, 0, 0, setOpacity, 0 },
                new float [] { 0, 0, 0,          0, 1 }
            };

            System.Drawing.Imaging.ColorMatrix clrMatrix =
                new System.Drawing.Imaging.ColorMatrix(setColrMartix);
            System.Drawing.Imaging.ImageAttributes setImage =
                new System.Drawing.Imaging.ImageAttributes();
            setImage.SetColorMatrix(clrMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default,
                                    System.Drawing.Imaging.ColorAdjustType.Bitmap);

            newGrp.DrawImage(orgImg, 0, 0, orgImg.Width, orgImg.Height);

            float orw = (float)(orgImg.Width * 0.3);
            float orh = (float)(orgImg.Height * 0.4);
            float mix = (float)((orgImg.Width / 2) + (orw / 2));
            float miy = (float)((orgImg.Height / 2) + (orh / 2) + ((orh / 2) / 2));
            float msw = markImg.Width;
            float msh = markImg.Height;

            newGrp.DrawImage(markImg, new Rectangle((int)mix, (int)miy, (int)orw, (int)orh),
                             0.0F, 0.0F, msw, msh, GraphicsUnit.Pixel, setImage);

            PictureBox NewMarkImage = new PictureBox();

            NewMarkImage.Image = tmpImg;
            return(NewMarkImage);
        }
コード例 #30
0
ファイル: ImageEx.cs プロジェクト: adison/Tank-Wars
        internal static void RGBToBGR(this Image bmp)
        {
            System.Drawing.Imaging.ImageAttributes ia = new System.Drawing.Imaging.ImageAttributes();
            System.Drawing.Imaging.ColorMatrix cm = new System.Drawing.Imaging.ColorMatrix(rgbtobgr);

            ia.SetColorMatrix(cm);
            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp))
            {
                g.DrawImage(bmp, new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, bmp.Width, bmp.Height, System.Drawing.GraphicsUnit.Pixel, ia);
            }
        }
コード例 #31
0
        internal static void RGBToBGR(this Image bmp)
        {
            System.Drawing.Imaging.ImageAttributes ia = new System.Drawing.Imaging.ImageAttributes();
            System.Drawing.Imaging.ColorMatrix     cm = new System.Drawing.Imaging.ColorMatrix(rgbtobgr);

            ia.SetColorMatrix(cm);
            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp))
            {
                g.DrawImage(bmp, new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, bmp.Width, bmp.Height, System.Drawing.GraphicsUnit.Pixel, ia);
            }
        }
コード例 #32
0
ファイル: BitMapHelpers.cs プロジェクト: wmeacham/EDDiscovery
        public static Bitmap ScaleColourInBitmap(Bitmap source, System.Drawing.Imaging.ColorMatrix cm)
        {
            Bitmap newmap = new Bitmap(source.Width, source.Height);

            System.Drawing.Imaging.ImageAttributes ia = new System.Drawing.Imaging.ImageAttributes();
            ia.SetColorMatrix(cm);

            using (Graphics gr = Graphics.FromImage(newmap))
                gr.DrawImage(source, new Rectangle(0, 0, source.Width, source.Height), 0, 0, source.Width, source.Height, GraphicsUnit.Pixel, ia);

            return(newmap);
        }
コード例 #33
0
 public static Image SetImgOpacity(Image imgPic, float imgOpac)
 {
     Bitmap bmpPic = new Bitmap(imgPic.Width, imgPic.Height);
     Graphics gfxPic = Graphics.FromImage(bmpPic);
     System.Drawing.Imaging.ColorMatrix cmxPic = new System.Drawing.Imaging.ColorMatrix();
     cmxPic.Matrix33 = imgOpac;
     System.Drawing.Imaging.ImageAttributes iaPic = new System.Drawing.Imaging.ImageAttributes();
     iaPic.SetColorMatrix(cmxPic, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap);
     gfxPic.DrawImage(imgPic, new Rectangle(0, 0, bmpPic.Width, bmpPic.Height), 0, 0, imgPic.Width, imgPic.Height, GraphicsUnit.Pixel, iaPic);
     gfxPic.Dispose();
     return bmpPic;
 }
コード例 #34
0
 public static System.Drawing.Bitmap ChangeOpacity(System.Drawing.Bitmap image, double opacityvalue)
 {
     System.Drawing.Bitmap              bmp         = new System.Drawing.Bitmap((int)image.Width, (int)image.Height); // Determining Width and Height of Source Image
     System.Drawing.Graphics            graphics    = System.Drawing.Graphics.FromImage(bmp);
     System.Drawing.Imaging.ColorMatrix colormatrix = new System.Drawing.Imaging.ColorMatrix();
     colormatrix.Matrix33 = (float)GetOpacity(opacityvalue);
     System.Drawing.Imaging.ImageAttributes imgAttribute = new System.Drawing.Imaging.ImageAttributes();
     imgAttribute.SetColorMatrix(colormatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap);
     graphics.DrawImage(image, new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, image.Width, image.Height, System.Drawing.GraphicsUnit.Pixel, imgAttribute);
     graphics.Dispose();   // Releasing all resource used by graphics
     return(bmp);
 }
コード例 #35
0
        public void UpdateSpriteScreen(Size imageSize)
        {
            pcbSprite.Image?.Dispose();
            Bitmap Image = new Bitmap(imageSize.Width, imageSize.Height);

            using (Graphics g = Graphics.FromImage(Image))
            {
                if (Sprite != null)
                {
                    if (UseText)
                    {
                        Bitmap bm = ConvertStringToImage(Sprite.DisplayText);
                        if (bm != null)
                        {
                            int x = (Image.Width / 2) - (bm.Width / 2);
                            int y = (Image.Height / 2) - (bm.Height / 2);
                            g.DrawImage(bm, x, y);
                            bm.Dispose();
                        }
                    }
                    else
                    {
                        foreach (Tile t in Sprite.Tiles)
                        {
                            int xDraw = (imageSize.Width / 2 - 8) + t.XOffset;
                            int yDraw = (imageSize.Height / 2 - 8) + t.YOffset;

                            int xGet = t.Map16Number % 16 * 16;
                            int yGet = (t.Map16Number / 16) * 16;

                            Image img = Map16Data.Image.Clone(new Rectangle(xGet, yGet, 16, 16), System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                            System.Drawing.Imaging.ImageAttributes attr = new System.Drawing.Imaging.ImageAttributes();
                            if (t.Selected)
                            {
                                attr.SetColorMatrix(new System.Drawing.Imaging.ColorMatrix(new float[][]
                                {
                                    new float[] { -1f, 0, 0, 0, 0 },
                                    new float[] { 0, -1f, 0, 0, 0 },
                                    new float[] { 0, 0, -1f, 0, 0 },
                                    new float[] { 0, 0, 0, +1f, 0 },
                                    new float[] { 1, 1, 1, 0, +1f },
                                }));
                            }

                            g.DrawImage(img, new Rectangle(xDraw, yDraw, 16, 16), 0, 0, 16, 16, GraphicsUnit.Pixel, attr);
                        }
                    }
                }
            }

            pcbSprite.Image = Image;
        }
コード例 #36
0
 private static void Init()
 {
     float[][] matrix = { 
     new   float[]   {0.299f,   0.299f,   0.299f,   0,   0},                
     new   float[]   {0.587f,   0.587f,   0.587f,   0,   0},                
     new   float[]   {0.114f,   0.114f,   0.114f,   0,   0},                
     new   float[]   {0,   0,   0,   1,   0},                  
     new   float[]   {0,   0,   0,   0,   1}
     };
     cm = new System.Drawing.Imaging.ColorMatrix(matrix);
     toGray = new System.Drawing.Imaging.ImageAttributes();
     toGray.SetColorMatrix(cm);
 }
コード例 #37
0
 public static System.Drawing.Bitmap ConvertSepiaTone(System.Drawing.Bitmap Image)
 {
     System.Drawing.Bitmap TempBitmap = Image;
     System.Drawing.Bitmap NewBitmap = new System.Drawing.Bitmap(TempBitmap.Width, TempBitmap.Height);
     System.Drawing.Graphics NewGraphics = System.Drawing.Graphics.FromImage(NewBitmap);
     float[][] FloatColorMatrix ={
             new float[] {.393f, .349f, .272f, 0, 0},
             new float[] {.769f, .686f, .534f, 0, 0},
             new float[] {.189f, .168f, .131f, 0, 0},
             new float[] {0, 0, 0, 1, 0},
             new float[] {0, 0, 0, 0, 1}
         };
     System.Drawing.Imaging.ColorMatrix NewColorMatrix = new System.Drawing.Imaging.ColorMatrix(FloatColorMatrix);
     System.Drawing.Imaging.ImageAttributes Attributes = new System.Drawing.Imaging.ImageAttributes();
     Attributes.SetColorMatrix(NewColorMatrix);
     NewGraphics.DrawImage(TempBitmap, new System.Drawing.Rectangle(0, 0, TempBitmap.Width, TempBitmap.Height), 0, 0, TempBitmap.Width, TempBitmap.Height, System.Drawing.GraphicsUnit.Pixel, Attributes);
     NewGraphics.Dispose();
     return NewBitmap;
 }
コード例 #38
0
        public static System.Drawing.Bitmap ConvertBlackAndWhite(System.Drawing.Image TempImage)
        {
            System.Drawing.Imaging.ImageFormat ImageFormat = TempImage.RawFormat;
            System.Drawing.Bitmap TempBitmap = new System.Drawing.Bitmap(TempImage, TempImage.Width, TempImage.Height);

            System.Drawing.Bitmap NewBitmap = new System.Drawing.Bitmap(TempBitmap.Width, TempBitmap.Height);
            System.Drawing.Graphics NewGraphics = System.Drawing.Graphics.FromImage(NewBitmap);
            float[][] FloatColorMatrix ={
                    new float[] {.3f, .3f, .3f, 0, 0},
                    new float[] {.59f, .59f, .59f, 0, 0},
                    new float[] {.11f, .11f, .11f, 0, 0},
                    new float[] {0, 0, 0, 1, 0},
                    new float[] {0, 0, 0, 0, 1}
                };

            System.Drawing.Imaging.ColorMatrix NewColorMatrix = new System.Drawing.Imaging.ColorMatrix(FloatColorMatrix);
            System.Drawing.Imaging.ImageAttributes Attributes = new System.Drawing.Imaging.ImageAttributes();
            Attributes.SetColorMatrix(NewColorMatrix);
            NewGraphics.DrawImage(TempBitmap, new System.Drawing.Rectangle(0, 0, TempBitmap.Width, TempBitmap.Height), 0, 0, TempBitmap.Width, TempBitmap.Height, System.Drawing.GraphicsUnit.Pixel, Attributes);
            NewGraphics.Dispose();
            return NewBitmap;
            //NewBitmap.Save(NewFileName, ImageFormat);
        }
コード例 #39
0
        internal static void PaintBackgroundImage(Graphics g, Rectangle targetRect, Image backgroundImage, eBackgroundImagePosition backgroundImagePosition, int backgroundImageAlpha)
        {
            if (backgroundImage == null)
                return;

            Rectangle r = targetRect;
            System.Drawing.Imaging.ImageAttributes imageAtt = null;

            if (backgroundImageAlpha != 255)
            {
                float[][] matrixItems ={ 
                   new float[] {1, 0, 0, 0, 0},
                   new float[] {0, 1, 0, 0, 0},
                   new float[] {0, 0, 1, 0, 0},
                   new float[] {0, 0, 0, (float)backgroundImageAlpha/255, 0}, 
                   new float[] {0, 0, 0, 0, 1}};
                System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(matrixItems);

                //System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix();
                //colorMatrix.Matrix33 = 255 - backgroundImageAlpha;
                imageAtt = new System.Drawing.Imaging.ImageAttributes();
                imageAtt.SetColorMatrix(colorMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap);
            }

            switch (backgroundImagePosition)
            {
                case eBackgroundImagePosition.Stretch:
                    {
                        if (imageAtt != null)
                            g.DrawImage(backgroundImage, r, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel, imageAtt);
                        else
                            g.DrawImage(backgroundImage, r, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel);
                        break;
                    }
                case eBackgroundImagePosition.CenterLeft:
                case eBackgroundImagePosition.CenterRight:
                    {
                        Rectangle destRect = new Rectangle(r.X, r.Y, backgroundImage.Width, backgroundImage.Height);
                        if (r.Width > backgroundImage.Width && backgroundImagePosition == eBackgroundImagePosition.CenterRight)
                            destRect.X += (r.Width - backgroundImage.Width);
                        destRect.Y += (r.Height - backgroundImage.Height) / 2;
                        if (imageAtt != null)
                            g.DrawImage(backgroundImage, destRect, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel, imageAtt);
                        else
                            g.DrawImage(backgroundImage, destRect, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel);

                        break;
                    }
                case eBackgroundImagePosition.Center:
                    {
                        Rectangle destRect = new Rectangle(r.X, r.Y, backgroundImage.Width, backgroundImage.Height);
                        if (r.Width > backgroundImage.Width)
                            destRect.X += (r.Width - backgroundImage.Width) / 2;
                        if (r.Height > backgroundImage.Height)
                            destRect.Y += (r.Height - backgroundImage.Height) / 2;
                        if (imageAtt != null)
                            g.DrawImage(backgroundImage, destRect, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel, imageAtt);
                        else
                            g.DrawImage(backgroundImage, destRect, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel);
                        break;
                    }
                case eBackgroundImagePosition.TopLeft:
                case eBackgroundImagePosition.TopRight:
                case eBackgroundImagePosition.BottomLeft:
                case eBackgroundImagePosition.BottomRight:
                    {
                        Rectangle destRect = new Rectangle(r.X, r.Y, backgroundImage.Width, backgroundImage.Height);
                        if (backgroundImagePosition == eBackgroundImagePosition.TopRight)
                            destRect.X = r.Right - backgroundImage.Width;
                        else if (backgroundImagePosition == eBackgroundImagePosition.BottomLeft)
                            destRect.Y = r.Bottom - backgroundImage.Height;
                        else if (backgroundImagePosition == eBackgroundImagePosition.BottomRight)
                        {
                            destRect.Y = r.Bottom - backgroundImage.Height;
                            destRect.X = r.Right - backgroundImage.Width;
                        }

                        if (imageAtt != null)
                            g.DrawImage(backgroundImage, destRect, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel, imageAtt);
                        else
                            g.DrawImage(backgroundImage, destRect, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel);
                        break;
                    }
                case eBackgroundImagePosition.Tile:
                    {
                        if (imageAtt != null)
                        {
                            if (r.Width > backgroundImage.Width || r.Height > backgroundImage.Height)
                            {
                                int x = r.X, y = r.Y;
                                while (y < r.Bottom)
                                {
                                    while (x < r.Right)
                                    {
                                        Rectangle destRect = new Rectangle(x, y, backgroundImage.Width, backgroundImage.Height);
                                        if (destRect.Right > r.Right)
                                            destRect.Width = destRect.Width - (destRect.Right - r.Right);
                                        if (destRect.Bottom > r.Bottom)
                                            destRect.Height = destRect.Height - (destRect.Bottom - r.Bottom);
                                        g.DrawImage(backgroundImage, destRect, 0, 0, destRect.Width, destRect.Height, GraphicsUnit.Pixel, imageAtt);
                                        x += backgroundImage.Width;
                                    }
                                    x = r.X;
                                    y += backgroundImage.Height;
                                }
                            }
                            else
                            {
                                g.DrawImage(backgroundImage, new Rectangle(0, 0, backgroundImage.Width, backgroundImage.Height), 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel, imageAtt);
                            }
                        }
                        else
                        {
                            SmoothingMode sm = g.SmoothingMode;
                            g.SmoothingMode = SmoothingMode.None;
                            using (TextureBrush brush = new TextureBrush(backgroundImage))
                            {
                                brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile;
                                g.FillRectangle(brush, r);
                            }
                            g.SmoothingMode = sm;
                        }
                        break;
                    }
            }
        }
コード例 #40
0
ファイル: ImageHelp.cs プロジェクト: WZDotCMS/WZDotCMS
        /// <summary>
        /// 加图片水印
        /// </summary>
        /// <param name="filename">文件名</param>
        /// <param name="watermarkFilename">水印文件名</param>
        /// <param name="watermarkStatus">图片水印位置:0=不使用 1=左上 2=中上 3=右上 4=左中 ... 9=右下</param>
        /// <param name="quality">是否是高质量图片 取值范围0--100</param> 
        /// <param name="watermarkTransparency">图片水印透明度 取值范围1--10 (10为不透明)</param>
        public static void AddImageSignPic(string Path, string filename, string watermarkFilename, int watermarkStatus, int quality, int watermarkTransparency)
        {
            System.Drawing.Image img = System.Drawing.Image.FromFile(Path);
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(img);

            //设置高质量插值法
            //g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
            //设置高质量,低速度呈现平滑程度
            //g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            System.Drawing.Image watermark = new System.Drawing.Bitmap(watermarkFilename);

            if (watermark.Height >= img.Height || watermark.Width >= img.Width)
            {
                return;
            }

            System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes();
            System.Drawing.Imaging.ColorMap colorMap = new System.Drawing.Imaging.ColorMap();

            colorMap.OldColor = System.Drawing.Color.FromArgb(255, 0, 255, 0);
            colorMap.NewColor = System.Drawing.Color.FromArgb(0, 0, 0, 0);
            System.Drawing.Imaging.ColorMap[] remapTable = { colorMap };

            imageAttributes.SetRemapTable(remapTable, System.Drawing.Imaging.ColorAdjustType.Bitmap);

            float transparency = 0.5F;
            if (watermarkTransparency >= 1 && watermarkTransparency <= 10)
            {
                transparency = (watermarkTransparency / 10.0F);
            }

            float[][] colorMatrixElements = {
                                                new float[] {1.0f,  0.0f,  0.0f,  0.0f, 0.0f},
                                                new float[] {0.0f,  1.0f,  0.0f,  0.0f, 0.0f},
                                                new float[] {0.0f,  0.0f,  1.0f,  0.0f, 0.0f},
                                                new float[] {0.0f,  0.0f,  0.0f,  transparency, 0.0f},
                                                new float[] {0.0f,  0.0f,  0.0f,  0.0f, 1.0f}
                                            };

            System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(colorMatrixElements);

            imageAttributes.SetColorMatrix(colorMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap);

            int xpos = 0;
            int ypos = 0;

            switch (watermarkStatus)
            {
                case 1:
                    xpos = (int)(img.Width * (float).01);
                    ypos = (int)(img.Height * (float).01);
                    break;
                case 2:
                    xpos = (int)((img.Width * (float).50) - (watermark.Width / 2));
                    ypos = (int)(img.Height * (float).01);
                    break;
                case 3:
                    xpos = (int)((img.Width * (float).99) - (watermark.Width));
                    ypos = (int)(img.Height * (float).01);
                    break;
                case 4:
                    xpos = (int)(img.Width * (float).01);
                    ypos = (int)((img.Height * (float).50) - (watermark.Height / 2));
                    break;
                case 5:
                    xpos = (int)((img.Width * (float).50) - (watermark.Width / 2));
                    ypos = (int)((img.Height * (float).50) - (watermark.Height / 2));
                    break;
                case 6:
                    xpos = (int)((img.Width * (float).99) - (watermark.Width));
                    ypos = (int)((img.Height * (float).50) - (watermark.Height / 2));
                    break;
                case 7:
                    xpos = (int)(img.Width * (float).01);
                    ypos = (int)((img.Height * (float).99) - watermark.Height);
                    break;
                case 8:
                    xpos = (int)((img.Width * (float).50) - (watermark.Width / 2));
                    ypos = (int)((img.Height * (float).99) - watermark.Height);
                    break;
                case 9:
                    xpos = (int)((img.Width * (float).99) - (watermark.Width));
                    ypos = (int)((img.Height * (float).99) - watermark.Height);
                    break;
            }

            g.DrawImage(watermark, new System.Drawing.Rectangle(xpos, ypos, watermark.Width, watermark.Height), 0, 0, watermark.Width, watermark.Height, System.Drawing.GraphicsUnit.Pixel, imageAttributes);

            System.Drawing.Imaging.ImageCodecInfo[] codecs = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders();
            System.Drawing.Imaging.ImageCodecInfo ici = null;
            foreach (System.Drawing.Imaging.ImageCodecInfo codec in codecs)
            {
                //if (codec.MimeType.IndexOf("jpeg") > -1)
                if (codec.MimeType.Contains("jpeg"))
                {
                    ici = codec;
                }
            }
            System.Drawing.Imaging.EncoderParameters encoderParams = new System.Drawing.Imaging.EncoderParameters();
            long[] qualityParam = new long[1];
            if (quality < 0 || quality > 100)
            {
                quality = 80;
            }
            qualityParam[0] = quality;

            System.Drawing.Imaging.EncoderParameter encoderParam = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qualityParam);
            encoderParams.Param[0] = encoderParam;

            if (ici != null)
            {
                img.Save(filename, ici, encoderParams);
            }
            else
            {
                img.Save(filename);
            }

            g.Dispose();
            img.Dispose();
            watermark.Dispose();
            imageAttributes.Dispose();
        }
コード例 #41
0
        /*public override void InternalClick(System.Windows.Forms.MouseButtons mb, System.Drawing.Point mpos)
        {
            if(m_Enabled && !this.DesignMode)
            {
                if(m_MenuVisibility==eMenuVisibility.VisibleIfRecentlyUsed && !m_RecentlyUsed && this.IsOnMenu)
                {
                    // Propagate to the top
                    m_RecentlyUsed=true;
                    BaseItem objItem=this.Parent;
                    while(objItem!=null)
                    {
                        IPersonalizedMenuItem ipm=objItem as IPersonalizedMenuItem;
                        if(ipm!=null)
                            ipm.RecentlyUsed=true;
                        objItem=objItem.Parent;
                    }
                }
            }

            // Since base item does not auto-collapse when clicked if it has subitems and it is on
            // pop-up we need to handle that here and check did user click on expand part of this button
            // and if they did not we need to raise click event and collapse the item.
            if(!this.IsOnMenu && (this.SubItemsCount>0 || this.PopupType==ePopupType.Container) && this.ShowSubItems && m_HotSubItem==null && !this.DesignMode && !this.IsOnMenuBar)
            {
                Rectangle r=new Rectangle(m_SubItemsRect.X,m_SubItemsRect.Y,m_SubItemsRect.Width,m_SubItemsRect.Height);
                r.Offset(m_Rect.X,m_Rect.Y);
                System.Windows.Forms.Control objCtrl=this.ContainerControl as System.Windows.Forms.Control;
                if(objCtrl==null)
                {
                    base.InternalClick(mb,mpos);
                    return;
                }
                Point p=objCtrl.PointToClient(mpos);
                objCtrl=null;
                if(!r.Contains(p))
                {
                    CollapseAll(this);
                    RaiseClick();
                }
            }
            else
                base.InternalClick(mb,mpos);
        }*/

        //		private void CreateDisabledImage()
        //		{
        //			if(m_Image==null && m_ImageIndex<0 && m_Icon==null)
        //				return;
        //			if(m_DisabledImage!=null)
        //				m_DisabledImage.Dispose();
        //			m_DisabledImage=null;
        //
        //			CompositeImage defaultImage=GetImage(ImageState.Default);
        //
        //			if(defaultImage==null)
        //				return;
        //			if(!defaultImage.IsIcon && defaultImage.Image!=null && defaultImage.Image is Bitmap)
        //			{
        //				m_DisabledImage=BarFunctions.CreateDisabledBitmap((Bitmap)defaultImage.Image);
        //			}
        //		}
        private void CreateDisabledImage()
        {
            if (m_Image == null && m_ImageIndex < 0 && m_Icon == null)
                return;
            if (m_DisabledImage != null)
                m_DisabledImage.Dispose();
            m_DisabledImage = null;
            if (m_DisabledIcon != null)
                m_DisabledIcon.Dispose();
            m_DisabledIcon = null;

            CompositeImage defaultImage = GetImage(ImageState.Default, Color.Black);

            if (defaultImage == null)
                return;

            if (this.GetOwner() is IOwner && ((IOwner)this.GetOwner()).DisabledImagesGrayScale)
            {
                if (defaultImage.IsIcon)
                {
                    m_DisabledIcon = BarFunctions.CreateDisabledIcon(defaultImage.Icon);
                }
                else
                {
                    m_DisabledImage = ImageHelper.CreateGrayScaleImage(defaultImage.Image as Bitmap);
                }
            }
            if (m_DisabledIcon != null || m_DisabledImage != null)
                return;

            // Use old algorithm if first one failed...
            System.Drawing.Imaging.PixelFormat pixelFormat = System.Drawing.Imaging.PixelFormat.Format32bppArgb;
            if (!defaultImage.IsIcon && defaultImage.Image != null)
                pixelFormat = defaultImage.Image.PixelFormat;

            if (pixelFormat == System.Drawing.Imaging.PixelFormat.Format1bppIndexed || pixelFormat == System.Drawing.Imaging.PixelFormat.Format4bppIndexed || pixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed)
                pixelFormat = System.Drawing.Imaging.PixelFormat.Format32bppArgb;

            Bitmap bmp = new Bitmap(defaultImage.Width, defaultImage.Height, pixelFormat);
            m_DisabledImage = new Bitmap(defaultImage.Width, defaultImage.Height, pixelFormat);

            Graphics g2 = Graphics.FromImage(bmp);
            using (SolidBrush brush = new SolidBrush(System.Drawing.Color.White))
                g2.FillRectangle(brush, 0, 0, defaultImage.Width, defaultImage.Height);
            //g2.DrawImage(defaultImage,0,0,defaultImage.Width,defaultImage.Height);
            defaultImage.DrawImage(g2, new Rectangle(0, 0, defaultImage.Width, defaultImage.Height));
            g2.Dispose();
            g2 = Graphics.FromImage(m_DisabledImage);

            bmp.MakeTransparent(System.Drawing.Color.White);
            eDotNetBarStyle effectiveStyle = EffectiveStyle;
            if ((effectiveStyle == eDotNetBarStyle.OfficeXP || effectiveStyle == eDotNetBarStyle.Office2003 || effectiveStyle == eDotNetBarStyle.VS2005 || BarFunctions.IsOffice2007Style(effectiveStyle)) && NativeFunctions.ColorDepth >= 8)
            {
                float[][] array = new float[5][];
                array[0] = new float[5] { 0, 0, 0, 0, 0 };
                array[1] = new float[5] { 0, 0, 0, 0, 0 };
                array[2] = new float[5] { 0, 0, 0, 0, 0 };
                array[3] = new float[5] { .5f, .5f, .5f, .5f, 0 };
                array[4] = new float[5] { 0, 0, 0, 0, 0 };
                System.Drawing.Imaging.ColorMatrix grayMatrix = new System.Drawing.Imaging.ColorMatrix(array);
                System.Drawing.Imaging.ImageAttributes disabledImageAttr = new System.Drawing.Imaging.ImageAttributes();
                disabledImageAttr.ClearColorKey();
                disabledImageAttr.SetColorMatrix(grayMatrix);
                g2.DrawImage(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, disabledImageAttr);
            }
            else
                System.Windows.Forms.ControlPaint.DrawImageDisabled(g2, bmp, 0, 0, ColorFunctions.MenuBackColor(g2));

            // Clean up
            g2.Dispose();
            g2 = null;
            bmp.Dispose();
            bmp = null;

            defaultImage.Dispose();
        }
コード例 #42
0
        private void PaintDotNet(ItemPaintArgs pa)
        {
            bool bIsOnMenu = pa.IsOnMenu;
            bool bIsOnMenuBar = pa.IsOnMenuBar;
            bool bThemed = this.IsThemed;

            if (!bIsOnMenu && !bIsOnMenuBar && bThemed)
            {
                ThemedButtonItemPainter.PaintButton(this, pa);
                return;
            }

            bool mouseOver = m_MouseOver;
            if (bIsOnMenu && this.Expanded && pa.ContainerControl != null && pa.ContainerControl.Parent != null)
            {
                if (!pa.ContainerControl.Parent.Bounds.Contains(System.Windows.Forms.Control.MousePosition))
                    mouseOver = true;
            }

            System.Drawing.Graphics g = pa.Graphics;

            Rectangle rect = Rectangle.Empty;
            Rectangle itemRect = new Rectangle(m_Rect.X, m_Rect.Y, m_Rect.Width, m_Rect.Height);
            Color textColor = System.Drawing.Color.Empty;

            if (mouseOver && !m_HotForeColor.IsEmpty)
                textColor = m_HotForeColor;
            else if (!m_ForeColor.IsEmpty)
                textColor = m_ForeColor;
            else if (mouseOver /*&& m_Checked*/ && !m_Expanded && /*!bIsOnMenu &&*/ m_HotTrackingStyle != eHotTrackingStyle.Image)
                textColor = pa.Colors.ItemHotText;
            else if (m_Expanded)
                textColor = pa.Colors.ItemExpandedText;
            else
            {
                if (bThemed && bIsOnMenuBar && pa.Colors.ItemText == SystemColors.ControlText)
                    textColor = SystemColors.MenuText;
                else
                    textColor = pa.Colors.ItemText;
            }

            Font objFont = null;

            eTextFormat objStringFormat = pa.ButtonStringFormat;
            CompositeImage objImage = GetImage();
            System.Drawing.Size imageSize = System.Drawing.Size.Empty;

            if (m_Font != null)
                objFont = m_Font;
            else
                objFont = GetFont(pa, false);

            // Calculate image position
            if (objImage != null)
            {
                imageSize = this.ImageSize;// objImage.Size;
                if (!bIsOnMenu && (m_ImagePosition == eImagePosition.Top || m_ImagePosition == eImagePosition.Bottom))
                    rect = new Rectangle(m_ImageDrawRect.X, m_ImageDrawRect.Y, itemRect.Width, m_ImageDrawRect.Height);
                else
                    rect = new Rectangle(m_ImageDrawRect.X, m_ImageDrawRect.Y, m_ImageDrawRect.Width, m_ImageDrawRect.Height);

                rect.Offset(itemRect.Left, itemRect.Top);
                //if(m_ButtonType==eButtonType.StateButton)
                //	rect.Offset(STATEBUTTON_SPACING+(m_ImageSize.Width-STATEBUTTON_SPACING)/2+(rect.Width-m_Image.Width*2)/2,(rect.Height-m_Image.Height)/2);
                //else
                rect.Offset((rect.Width - imageSize.Width) / 2, (rect.Height - imageSize.Height) / 2);

                rect.Width = imageSize.Width;
                rect.Height = imageSize.Height;
            }

            if (bIsOnMenu)
            {
                // Draw side bar
                if (this.MenuVisibility == eMenuVisibility.VisibleIfRecentlyUsed && !this.RecentlyUsed)
                {
                    if (!pa.Colors.MenuUnusedSide2.IsEmpty)
                    {
                        System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(new Rectangle(m_Rect.Left, m_Rect.Top, m_ImageDrawRect.Right, m_Rect.Height), pa.Colors.MenuUnusedSide, pa.Colors.MenuUnusedSide2, pa.Colors.MenuUnusedSideGradientAngle);
                        g.FillRectangle(gradient, m_Rect.Left, m_Rect.Top, m_ImageDrawRect.Right, m_Rect.Height);
                        gradient.Dispose();
                    }
                    else
                    {
                        using (SolidBrush mybrush = new SolidBrush(pa.Colors.MenuUnusedSide/*ColorFunctions.SideRecentlyBackColor(g)*/))
                            g.FillRectangle(mybrush, m_Rect.Left, m_Rect.Top, m_ImageDrawRect.Right, m_Rect.Height);
                    }
                }
                else
                {
                    if (!pa.Colors.MenuSide2.IsEmpty)
                    {
                        System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(new Rectangle(m_Rect.Left, m_Rect.Top, m_ImageDrawRect.Right, m_Rect.Height), pa.Colors.MenuSide, pa.Colors.MenuSide2, pa.Colors.MenuSideGradientAngle);
                        g.FillRectangle(gradient, m_Rect.Left, m_Rect.Top, m_ImageDrawRect.Right, m_Rect.Height);
                        gradient.Dispose();
                    }
                    else
                    {
                        using (SolidBrush mybrush = new SolidBrush(pa.Colors.MenuSide))
                            g.FillRectangle(mybrush, m_Rect.Left, m_Rect.Top, m_ImageDrawRect.Right, m_Rect.Height);
                    }
                }
                // Draw Background of the item
                //using(SolidBrush mybrush=new SolidBrush(pa.Colors.MenuBackground))
                //	g.FillRectangle(mybrush,m_Rect.Left+m_ImageDrawRect.Right,m_Rect.Top,m_Rect.Width-m_ImageDrawRect.Right,m_Rect.Height);
            }
            else
            {
                // Draw button background
                //if(bIsOnMenuBar)
                //	g.FillRectangle(SystemBrushes.Control,m_Rect);
                //else
                //	g.FillRectangle(new SolidBrush(ColorFunctions.ToolMenuFocusBackColor(g)),m_Rect);
                if (!pa.Colors.ItemBackground.IsEmpty)
                {
                    if (pa.Colors.ItemBackground2.IsEmpty)
                    {
                        using (SolidBrush mybrush = new SolidBrush(pa.Colors.ItemBackground))
                            g.FillRectangle(mybrush, m_Rect);
                    }
                    else
                    {
                        using (System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(this.DisplayRectangle, pa.Colors.ItemBackground, pa.Colors.ItemBackground2, pa.Colors.ItemBackgroundGradientAngle))
                            g.FillRectangle(gradient, this.DisplayRectangle);
                    }
                }
                else if (!GetEnabled(pa.ContainerControl) && !pa.Colors.ItemDisabledBackground.IsEmpty)
                {
                    using (SolidBrush mybrush = new SolidBrush(pa.Colors.ItemDisabledBackground))
                        g.FillRectangle(mybrush, m_Rect);
                }
            }

            if (GetEnabled(pa.ContainerControl) || this.DesignMode)
            {
                if (m_Expanded && !bIsOnMenu)
                {
                    // DotNet Style
                    if (pa.Colors.ItemExpandedBackground2.IsEmpty)
                    {
                        Rectangle rBack = new Rectangle(itemRect.Left, itemRect.Top, itemRect.Width, itemRect.Height);
                        if (pa.Colors.ItemExpandedShadow.IsEmpty)
                            rBack.Width -= 2;
                        using (SolidBrush mybrush = new SolidBrush(pa.Colors.ItemExpandedBackground))
                            g.FillRectangle(mybrush, rBack);
                    }
                    else
                    {
                        System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(new Rectangle(itemRect.Left, itemRect.Top, itemRect.Width - 2, itemRect.Height), pa.Colors.ItemExpandedBackground, pa.Colors.ItemExpandedBackground2, pa.Colors.ItemExpandedBackgroundGradientAngle);
                        Rectangle rBack = new Rectangle(itemRect.Left, itemRect.Top, itemRect.Width, itemRect.Height);
                        if (pa.Colors.ItemExpandedShadow.IsEmpty)
                            rBack.Width -= 2;
                        g.FillRectangle(gradient, rBack);
                        gradient.Dispose();
                    }
                    Point[] p;
                    if (m_Orientation == eOrientation.Horizontal && this.PopupSide == ePopupSide.Default)
                        p = new Point[4];
                    else
                        p = new Point[5];
                    p[0].X = itemRect.Left;
                    p[0].Y = itemRect.Top + itemRect.Height - 1;
                    p[1].X = itemRect.Left;
                    p[1].Y = itemRect.Top;
                    if (m_Orientation == eOrientation.Horizontal /*&& !pa.Colors.ItemExpandedShadow.IsEmpty*/)
                        p[2].X = itemRect.Left + itemRect.Width - 3;
                    else
                        p[2].X = itemRect.Left + itemRect.Width - 1;
                    p[2].Y = itemRect.Top;
                    if (m_Orientation == eOrientation.Horizontal /*&& !pa.Colors.ItemExpandedShadow.IsEmpty*/)
                        p[3].X = itemRect.Left + itemRect.Width - 3;
                    else
                        p[3].X = itemRect.Left + itemRect.Width - 1;

                    p[3].Y = itemRect.Top + itemRect.Height - 1;
                    if (m_Orientation == eOrientation.Vertical || this.PopupSide != ePopupSide.Default)
                    {
                        p[4].X = itemRect.Left;
                        p[4].Y = itemRect.Top + itemRect.Height - 1;
                    }

                    if (!pa.Colors.ItemExpandedBorder.IsEmpty)
                    {
                        using (Pen mypen = new Pen(pa.Colors.ItemExpandedBorder, 1))
                            g.DrawLines(mypen, p);
                    }
                    // Draw the shadow
                    if (!pa.Colors.ItemExpandedShadow.IsEmpty && m_Orientation == eOrientation.Horizontal)
                    {
                        using (SolidBrush shadow = new SolidBrush(pa.Colors.ItemExpandedShadow))
                            g.FillRectangle(shadow, itemRect.Left + itemRect.Width - 2, itemRect.Top + 2, 2, itemRect.Height - 2); // TODO: ADD GRADIENT SHADOW					
                    }
                }

                if ((mouseOver && m_HotTrackingStyle != eHotTrackingStyle.None) || m_Expanded && !bIsOnMenu)
                {
                    // Draw Mouse over marker
                    if (!m_Expanded || bIsOnMenu)
                    {
                        Rectangle r = itemRect;
                        if (bIsOnMenu)
                            r = new Rectangle(itemRect.Left + 1, itemRect.Top, itemRect.Width - 2, itemRect.Height);
                        if (this.DesignMode && this.Focused)
                        {
                            //g.FillRectangle(new SolidBrush(ColorFunctions.MenuBackColor(g)),r);
                            r = m_Rect;
                            r.Inflate(-1, -1);
                            DesignTime.DrawDesignTimeSelection(g, r, pa.Colors.ItemDesignTimeBorder);
                        }
                        else
                        {
                            if (m_MouseDown)
                            {
                                if (m_HotTrackingStyle == eHotTrackingStyle.Image)
                                {
                                    r = rect;
                                    r.Inflate(2, 2);
                                }
                                if (pa.Colors.ItemPressedBackground2.IsEmpty)
                                {
                                    using (SolidBrush mybrush = new SolidBrush(pa.Colors.ItemPressedBackground/*ColorFunctions.PressedBackColor(g)*/))
                                        g.FillRectangle(mybrush, r);
                                }
                                else
                                {
                                    System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemPressedBackground, pa.Colors.ItemPressedBackground2, pa.Colors.ItemPressedBackgroundGradientAngle);
                                    g.FillRectangle(gradient, r);
                                    gradient.Dispose();
                                }
                                using (Pen mypen = new Pen(pa.Colors.ItemPressedBorder, 1))
                                    NativeFunctions.DrawRectangle(g, mypen, r);
                            }
                            else if (m_HotTrackingStyle == eHotTrackingStyle.Image && !rect.IsEmpty)
                            {
                                Rectangle rImage = rect;
                                rImage.Inflate(2, 2);
                                if (!pa.Colors.ItemHotBackground2.IsEmpty)
                                {
                                    System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(rImage, pa.Colors.ItemHotBackground, pa.Colors.ItemHotBackground2, pa.Colors.ItemHotBackgroundGradientAngle);
                                    g.FillRectangle(gradient, rImage);
                                    gradient.Dispose();
                                }
                                else
                                {
                                    using (SolidBrush mybrush = new SolidBrush(pa.Colors.ItemHotBackground/*ColorFunctions.HoverBackColor(g)*/))
                                        g.FillRectangle(mybrush, rImage);
                                }
                                using (Pen mypen = new Pen(pa.Colors.ItemHotBorder, 1))
                                    NativeFunctions.DrawRectangle(g, mypen, rImage);
                            }
                            else
                            {
                                if (!pa.Colors.ItemCheckedBackground2.IsEmpty && m_Checked)
                                {
                                    System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemCheckedBackground2, pa.Colors.ItemCheckedBackground, pa.Colors.ItemCheckedBackgroundGradientAngle);
                                    g.FillRectangle(gradient, r);
                                    gradient.Dispose();
                                }
                                else
                                {
                                    if (!pa.Colors.ItemHotBackground2.IsEmpty)
                                    {
                                        System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemHotBackground, pa.Colors.ItemHotBackground2, pa.Colors.ItemHotBackgroundGradientAngle);
                                        g.FillRectangle(gradient, r);
                                        gradient.Dispose();
                                    }
                                    else
                                    {
                                        using (SolidBrush mybrush = new SolidBrush(pa.Colors.ItemHotBackground))
                                            g.FillRectangle(mybrush, r);
                                    }
                                }
                                using (Pen mypen = new Pen(pa.Colors.ItemHotBorder, 1))
                                    NativeFunctions.DrawRectangle(g, mypen, r);
                            }
                        }
                        // TODO: Beta 2 Hack for DrawRectangle Possible bug, need to verify
                        //r.Width-=1;
                        //r.Height-=1;
                        //g.DrawRectangle(SystemPens.Highlight,r);
                    }

                    // Image needs shadow when it has focus
                    if (objImage != null && m_ButtonStyle != eButtonStyle.TextOnlyAlways)
                    {
                        // We needed the image to stay "up" when button is expanded too so we removed the checking here
                        //if(m_MouseDown || (m_Expanded && !bIsOnMenu) || m_Checked && !this.IsOnCustomizeMenu && !this.IsOnCustomizeDialog)
                        if (m_MouseDown || m_Checked && !this.IsOnCustomizeMenu && !this.IsOnCustomizeDialog)
                        {
                            objImage.DrawImage(g, rect);// g.DrawImage(objImage,rect);//,0,0,imageSize.Width,imageSize.Height,System.Drawing.GraphicsUnit.Pixel);
                        }
                        else
                        {
                            if (NativeFunctions.ColorDepth >= 16 && EffectiveStyle != eDotNetBarStyle.Office2003)
                            {
                                float[][] array = new float[5][];
                                array[0] = new float[5] { 0, 0, 0, 0, 0 };
                                array[1] = new float[5] { 0, 0, 0, 0, 0 };
                                array[2] = new float[5] { 0, 0, 0, 0, 0 };
                                array[3] = new float[5] { .5f, .5f, .5f, .5f, 0 };
                                array[4] = new float[5] { 0, 0, 0, 0, 0 };
                                System.Drawing.Imaging.ColorMatrix grayMatrix = new System.Drawing.Imaging.ColorMatrix(array);
                                System.Drawing.Imaging.ImageAttributes disabledImageAttr = new System.Drawing.Imaging.ImageAttributes();
                                disabledImageAttr.ClearColorKey();
                                disabledImageAttr.SetColorMatrix(grayMatrix);

                                rect.Offset(1, 1);
                                //g.DrawImage(objImage,rect,0,0,objImage.Width,objImage.Height,GraphicsUnit.Pixel,disabledImageAttr);
                                objImage.DrawImage(g, rect, 0, 0, objImage.Width, objImage.Height, GraphicsUnit.Pixel, disabledImageAttr);
                                rect.Offset(-2, -2);
                                //g.DrawImage(objImage,rect);
                                objImage.DrawImage(g, rect);
                            }
                            else
                            {
                                if (EffectiveStyle == eDotNetBarStyle.OfficeXP)
                                    rect.Offset(-1, -1);
                                //g.DrawImage(objImage,rect);
                                objImage.DrawImage(g, rect);
                            }
                        }
                    }

                    if (bIsOnMenu && this.IsOnCustomizeMenu && m_Visible && !this.SystemItem)
                    {
                        // Draw check box if this item is visible
                        Rectangle r = new Rectangle(m_Rect.Left, m_Rect.Top, m_Rect.Height, m_Rect.Height);
                        r.Inflate(-1, -1);
                        //Color clr=g.GetNearestColor(Color.FromArgb(45,SystemColors.Highlight));
                        Color clr = pa.Colors.ItemCheckedBackground/*ColorFunctions.CheckBoxBackColor(g)*/;
                        if (mouseOver && !pa.Colors.ItemHotBackground2.IsEmpty)
                        {
                            System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemHotBackground, pa.Colors.ItemHotBackground2, pa.Colors.ItemHotBackgroundGradientAngle);
                            g.FillRectangle(gradient, r);
                            gradient.Dispose();
                        }
                        else
                        {
                            if (mouseOver)
                                clr = pa.Colors.ItemHotBackground;

                            if (!pa.Colors.ItemCheckedBackground2.IsEmpty && !mouseOver)
                            {
                                System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemCheckedBackground, pa.Colors.ItemCheckedBackground2, pa.Colors.ItemCheckedBackgroundGradientAngle);
                                g.FillRectangle(gradient, r);
                                gradient.Dispose();
                            }
                            else
                            {
                                SolidBrush objBrush = new SolidBrush(clr);
                                g.FillRectangle(objBrush, r);
                                objBrush.Dispose();
                            }
                        }
                    }
                }
                else
                {
                    if (objImage != null && m_ButtonStyle != eButtonStyle.TextOnlyAlways)
                    {
                        if (!m_Checked || this.IsOnCustomizeMenu)
                        {
                            if (m_HotTrackingStyle != eHotTrackingStyle.Color)
                            {
                                objImage.DrawImage(g, rect);
                            }
                            else
                            {
                                // Draw gray-scale image for this hover style...
                                float[][] array = new float[5][];
                                array[0] = new float[5] { 0.2125f, 0.2125f, 0.2125f, 0, 0 };
                                array[1] = new float[5] { 0.5f, 0.5f, 0.5f, 0, 0 };
                                array[2] = new float[5] { 0.0361f, 0.0361f, 0.0361f, 0, 0 };
                                array[3] = new float[5] { 0, 0, 0, 1, 0 };
                                array[4] = new float[5] { 0.2f, 0.2f, 0.2f, 0, 1 };
                                System.Drawing.Imaging.ColorMatrix grayMatrix = new System.Drawing.Imaging.ColorMatrix(array);
                                System.Drawing.Imaging.ImageAttributes att = new System.Drawing.Imaging.ImageAttributes();
                                att.SetColorMatrix(grayMatrix);
                                //g.DrawImage(objImage,rect,0,0,objImage.Width,objImage.Height,GraphicsUnit.Pixel,att);
                                objImage.DrawImage(g, rect, 0, 0, objImage.Width, objImage.Height, GraphicsUnit.Pixel, att);
                            }
                        }
                        else
                        {
                            if ((m_Checked && bIsOnMenu || !this.Expanded) && !this.IsOnCustomizeDialog)
                            {
                                Rectangle r;
                                if (bIsOnMenu)
                                    r = new Rectangle(m_Rect.X + 1, m_Rect.Y, m_ImageDrawRect.Width - 2, m_Rect.Height);
                                else if (m_HotTrackingStyle == eHotTrackingStyle.Image)
                                {
                                    r = rect;
                                    r.Inflate(2, 2);
                                }
                                else
                                    r = m_Rect;
                                if (bIsOnMenu)
                                    r.Inflate(-1, -1);
                                Color clr;
                                if (mouseOver && m_HotTrackingStyle != eHotTrackingStyle.None)
                                {
                                    if (m_Checked && !pa.Colors.ItemCheckedBackground2.IsEmpty)
                                    {
                                        System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemCheckedBackground2, pa.Colors.ItemCheckedBackground, pa.Colors.ItemCheckedBackgroundGradientAngle);
                                        g.FillRectangle(gradient, r);
                                        gradient.Dispose();
                                        clr = System.Drawing.Color.Empty;
                                    }
                                    else
                                    {
                                        if (!pa.Colors.ItemHotBackground2.IsEmpty)
                                        {
                                            System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemHotBackground, pa.Colors.ItemHotBackground2, pa.Colors.ItemHotBackgroundGradientAngle);
                                            g.FillRectangle(gradient, r);
                                            gradient.Dispose();
                                            clr = System.Drawing.Color.Empty;
                                        }
                                        else
                                            clr = System.Windows.Forms.ControlPaint.Dark(pa.Colors.ItemHotBackground);
                                    }
                                }
                                else
                                {
                                    if (!pa.Colors.ItemCheckedBackground2.IsEmpty)
                                    {
                                        System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemCheckedBackground, pa.Colors.ItemCheckedBackground2, pa.Colors.ItemCheckedBackgroundGradientAngle);
                                        g.FillRectangle(gradient, r);
                                        gradient.Dispose();
                                        clr = System.Drawing.Color.Empty;
                                    }
                                    else
                                        clr = pa.Colors.ItemCheckedBackground/*ColorFunctions.CheckBoxBackColor(g)*/;
                                }
                                if (!clr.IsEmpty)
                                {
                                    SolidBrush objBrush = new SolidBrush(clr);
                                    g.FillRectangle(objBrush, r);
                                    objBrush.Dispose();
                                }
                            }
                            objImage.DrawImage(g, rect);
                        }
                    }
                    if (bIsOnMenu && this.IsOnCustomizeMenu && m_Visible && !this.SystemItem)
                    {
                        // Draw check box if this item is visible
                        Rectangle r = new Rectangle(m_Rect.Left, m_Rect.Top, m_Rect.Height, m_Rect.Height);
                        r.Inflate(-1, -1);
                        //Color clr=g.GetNearestColor(Color.FromArgb(96,ColorFunctions.HoverBackColor()));
                        if (pa.Colors.ItemCheckedBackground2.IsEmpty)
                        {
                            Color clr = pa.Colors.ItemCheckedBackground/*ColorFunctions.CheckBoxBackColor(g)*/;
                            SolidBrush objBrush = new SolidBrush(clr);
                            g.FillRectangle(objBrush, r);
                            objBrush.Dispose();
                        }
                        else
                        {
                            System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemCheckedBackground, pa.Colors.ItemCheckedBackground2, pa.Colors.ItemCheckedBackgroundGradientAngle);
                            g.FillRectangle(gradient, r);
                            gradient.Dispose();
                        }
                    }
                    else if (m_Checked && !bIsOnMenu && objImage == null)
                    {
                        Rectangle r = m_Rect;
                        // TODO: In 9188 GetNearestColor on the Graphics that were taken directly from Paint event did not work correctly. Check in future versions...
                        // Draw background
                        //Color clr=g.GetNearestColor(Color.FromArgb(96,ColorFunctions.HoverBackColor(g)));
                        Color clr;
                        if (mouseOver && m_HotTrackingStyle != eHotTrackingStyle.None)
                        {
                            if (!pa.Colors.ItemCheckedBackground2.IsEmpty)
                            {
                                System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemCheckedBackground2, pa.Colors.ItemCheckedBackground, pa.Colors.ItemCheckedBackgroundGradientAngle);
                                g.FillRectangle(gradient, r);
                                gradient.Dispose();
                                clr = System.Drawing.Color.Empty;
                            }
                            else
                            {
                                if (!pa.Colors.ItemHotBackground2.IsEmpty)
                                {
                                    System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemHotBackground, pa.Colors.ItemHotBackground2, pa.Colors.ItemHotBackgroundGradientAngle);
                                    g.FillRectangle(gradient, r);
                                    gradient.Dispose();
                                    clr = System.Drawing.Color.Empty;
                                }
                                else
                                    clr = pa.Colors.ItemHotBackground;
                            }
                        }
                        else
                        {
                            if (!pa.Colors.ItemCheckedBackground2.IsEmpty)
                            {
                                System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemCheckedBackground, pa.Colors.ItemCheckedBackground2, pa.Colors.ItemCheckedBackgroundGradientAngle);
                                g.FillRectangle(gradient, r);
                                gradient.Dispose();
                                clr = System.Drawing.Color.Empty;
                            }
                            else
                                clr = pa.Colors.ItemCheckedBackground;
                        }
                        if (!clr.IsEmpty)
                        {
                            SolidBrush objBrush = new SolidBrush(clr);
                            g.FillRectangle(objBrush, r);
                            objBrush.Dispose();
                        }
                    }
                }

                if (bIsOnMenu && this.IsOnCustomizeMenu && m_Visible && !this.SystemItem)
                {
                    Rectangle r = new Rectangle(m_Rect.Left, m_Rect.Top, m_Rect.Height, m_Rect.Height);
                    r.Inflate(-1, -1);
                    //Color clr=g.GetNearestColor(Color.FromArgb(200,SystemColors.Highlight));
                    Color clr = pa.Colors.ItemCheckedBorder/*SystemColors.Highlight*/;
                    Pen objPen = new Pen(clr, 1);
                    // TODO: Beta 2 fix --> g.DrawRectangle(objPen,r);
                    NativeFunctions.DrawRectangle(g, objPen, r);

                    objPen.Dispose();
                    objPen = new Pen(pa.Colors.ItemCheckedText);
                    // Draw checker...
                    Point[] pt = new Point[3];
                    pt[0].X = r.Left + (r.Width - 5) / 2 - 1;
                    pt[0].Y = r.Top + (r.Height - 6) / 2 + 3;
                    pt[1].X = pt[0].X + 2;
                    pt[1].Y = pt[0].Y + 2;
                    pt[2].X = pt[1].X + 4;
                    pt[2].Y = pt[1].Y - 4;
                    g.DrawLines(objPen/*SystemPens.ControlText*/, pt);
                    pt[0].X++;
                    pt[1].X++;
                    pt[2].X++;
                    g.DrawLines(objPen/*SystemPens.ControlText*/, pt);
                    objPen.Dispose();
                }

                if (m_Checked && !this.IsOnCustomizeMenu && !this.IsOnCustomizeDialog)
                {
                    Rectangle r;

                    if (bIsOnMenu)
                        r = new Rectangle(m_Rect.X + 1, m_Rect.Y, m_ImageDrawRect.Width - 2, m_Rect.Height);
                    else if (m_HotTrackingStyle == eHotTrackingStyle.Image)
                    {
                        r = rect;
                        r.Inflate(2, 2);
                    }
                    else
                        r = new Rectangle(m_Rect.X, m_Rect.Y, m_Rect.Width, m_Rect.Height);
                    if (bIsOnMenu)
                        r.Inflate(-1, -1);

                    // Draw line around...
                    if (bIsOnMenu || !this.Expanded)
                    {
                        if (objImage == null || m_ButtonStyle == eButtonStyle.TextOnlyAlways)
                        {
                            if (mouseOver)
                            {
                                if (m_Checked && !pa.Colors.ItemCheckedBackground2.IsEmpty)
                                {
                                    System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemCheckedBackground2, pa.Colors.ItemCheckedBackground, pa.Colors.ItemCheckedBackgroundGradientAngle);
                                    g.FillRectangle(gradient, r);
                                    gradient.Dispose();
                                }
                                else
                                {
                                    if (!pa.Colors.ItemHotBackground2.IsEmpty)
                                    {
                                        System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemHotBackground, pa.Colors.ItemHotBackground2, pa.Colors.ItemHotBackgroundGradientAngle);
                                        g.FillRectangle(gradient, r);
                                        gradient.Dispose();
                                    }
                                    else
                                    {
                                        using (SolidBrush mybrush = new SolidBrush(pa.Colors.ItemHotBackground))
                                            g.FillRectangle(mybrush, r);
                                    }
                                }
                            }
                            else
                            {
                                if (pa.Colors.ItemCheckedBackground2.IsEmpty)
                                {
                                    using (SolidBrush mybrush = new SolidBrush(pa.Colors.ItemCheckedBackground))
                                        g.FillRectangle(mybrush, r);
                                }
                                else
                                {
                                    System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemCheckedBackground, pa.Colors.ItemCheckedBackground2, pa.Colors.ItemCheckedBackgroundGradientAngle);
                                    g.FillRectangle(gradient, r);
                                    gradient.Dispose();
                                }
                            }
                        }

                        //Color clr=g.GetNearestColor(Color.FromArgb(200,SystemColors.Highlight));
                        Color clr = pa.Colors.ItemCheckedBorder/*SystemColors.Highlight*/;
                        Pen objPen = new Pen(clr, 1);
                        // TODO: Beta 2 fix  ---> g.DrawRectangle(objPen,r);
                        NativeFunctions.DrawRectangle(g, objPen, r);

                        objPen.Dispose();
                    }

                    if ((objImage == null || m_ButtonStyle == eButtonStyle.TextOnlyAlways) && bIsOnMenu)
                    {
                        // Draw checker...
                        Pen pen = new Pen(pa.Colors.ItemCheckedText);
                        Point[] pt = new Point[3];
                        pt[0].X = r.Left + (r.Width - 5) / 2 - 1;
                        pt[0].Y = r.Top + (r.Height - 6) / 2 + 3;
                        pt[1].X = pt[0].X + 2;
                        pt[1].Y = pt[0].Y + 2;
                        pt[2].X = pt[1].X + 4;
                        pt[2].Y = pt[1].Y - 4;
                        g.DrawLines(pen/*SystemPens.ControlText*/, pt);
                        pt[0].X++;
                        //pt[0].Y
                        pt[1].X++;
                        //pt[1].Y;
                        pt[2].X++;
                        //pt[2].Y;
                        g.DrawLines(pen/*SystemPens.ControlText*/, pt);
                        pen.Dispose();
                    }
                }
            }
            else
            {
                if (bIsOnMenu && mouseOver && m_HotTrackingStyle == eHotTrackingStyle.Default)
                {
                    Rectangle r = new Rectangle(itemRect.Left + 1, itemRect.Top, itemRect.Width - 2, itemRect.Height);
                    using (Pen mypen = new Pen(pa.Colors.ItemHotBorder, 1))
                        NativeFunctions.DrawRectangle(g, mypen, r);
                }

                // Replicated code from above to draw the item checked box
                if (m_Checked && !this.IsOnCustomizeMenu && !this.IsOnCustomizeDialog)
                {
                    Rectangle r;

                    if (bIsOnMenu)
                        r = new Rectangle(m_Rect.X + 1, m_Rect.Y, m_ImageDrawRect.Width - 2, m_Rect.Height);
                    else if (m_HotTrackingStyle == eHotTrackingStyle.Image)
                    {
                        r = rect;
                        r.Inflate(2, 2);
                    }
                    else
                        r = new Rectangle(m_Rect.X, m_Rect.Y, m_Rect.Width, m_Rect.Height);
                    if (bIsOnMenu)
                        r.Inflate(-1, -1);

                    // Draw line around...
                    if (bIsOnMenu || !this.Expanded)
                    {
                        Color clr = pa.Colors.ItemDisabledText;
                        Pen objPen = new Pen(clr, 1);
                        NativeFunctions.DrawRectangle(g, objPen, r);
                        objPen.Dispose();
                    }

                    if ((objImage == null || m_ButtonStyle == eButtonStyle.TextOnlyAlways) && bIsOnMenu)
                    {
                        // Draw checker...
                        Pen pen = new Pen(pa.Colors.ItemDisabledText);
                        Point[] pt = new Point[3];
                        pt[0].X = r.Left + (r.Width - 5) / 2 - 1;
                        pt[0].Y = r.Top + (r.Height - 6) / 2 + 3;
                        pt[1].X = pt[0].X + 2;
                        pt[1].Y = pt[0].Y + 2;
                        pt[2].X = pt[1].X + 4;
                        pt[2].Y = pt[1].Y - 4;
                        g.DrawLines(pen, pt);
                        pt[0].X++;
                        //pt[0].Y
                        pt[1].X++;
                        //pt[1].Y;
                        pt[2].X++;
                        //pt[2].Y;
                        g.DrawLines(pen, pt);
                        pen.Dispose();
                    }
                }
                textColor = pa.Colors.ItemDisabledText;
                if (objImage != null && m_ButtonStyle != eButtonStyle.TextOnlyAlways)
                {
                    // Draw disabled image
                    objImage.DrawImage(g, rect);
                }
            }

            // Draw menu item text
            if (bIsOnMenu || m_ButtonStyle != eButtonStyle.Default || objImage == null || (!bIsOnMenu && (m_ImagePosition == eImagePosition.Top || m_ImagePosition == eImagePosition.Bottom)) /*|| !this.IsOnBar*/) // Commented out becouse it caused text to be drawn if item is not on bar no matter what
            {
                if (bIsOnMenu)
                    rect = new Rectangle(m_TextDrawRect.X, m_TextDrawRect.Y, itemRect.Width - m_ImageDrawRect.Right - 26, m_TextDrawRect.Height);
                else
                {
                    rect = m_TextDrawRect;
                    if (m_ImagePosition == eImagePosition.Top || m_ImagePosition == eImagePosition.Bottom)
                    {
                        if (m_Orientation == eOrientation.Vertical)
                        {
                            rect = new Rectangle(m_TextDrawRect.X, m_TextDrawRect.Y, m_TextDrawRect.Width, m_TextDrawRect.Height);
                        }
                        else
                        {
                            rect = new Rectangle(m_TextDrawRect.X, m_TextDrawRect.Y, itemRect.Width, m_TextDrawRect.Height);
                            if ((this.SubItems.Count > 0 || this.PopupType == ePopupType.Container) && this.ShowSubItems)
                                rect.Width -= 10;
                        }

                        objStringFormat |= eTextFormat.HorizontalCenter;
                    }
                    else if (bIsOnMenuBar && objImage == null)
                        objStringFormat |= eTextFormat.HorizontalCenter;

                    if (m_MouseDown && m_HotTrackingStyle != eHotTrackingStyle.Image)
                    {
                        if (m_ForeColor.IsEmpty)
                        {
                            textColor = pa.Colors.ItemPressedText;
                        }
                        else
                        {
                            textColor = System.Windows.Forms.ControlPaint.Light(m_ForeColor);
                        }
                    }
                }

                rect.Offset(itemRect.Left, itemRect.Top);

                if (m_Orientation == eOrientation.Vertical && !bIsOnMenu)
                {
                    g.RotateTransform(90);
                    TextDrawing.DrawStringLegacy(g, m_Text, objFont, textColor, new Rectangle(rect.Top, -rect.Right, rect.Height, rect.Width), objStringFormat);
                    g.ResetTransform();
                }
                else
                {
                    if (rect.Right > m_Rect.Right)
                        rect.Width = m_Rect.Right - rect.Left;
                    TextDrawing.DrawString(g, m_Text, objFont, textColor, rect, objStringFormat);
                    if (!this.DesignMode && this.Focused && !bIsOnMenu && !bIsOnMenuBar)
                    {
                        //SizeF szf=g.MeasureString(m_Text,objFont,rect.Width,objStringFormat);
                        Rectangle r = rect;
                        //r.Width=(int)Math.Ceiling(szf.Width);
                        //r.Height=(int)Math.Ceiling(szf.Height);
                        //r.Inflate(1,1);
                        System.Windows.Forms.ControlPaint.DrawFocusRectangle(g, r);
                    }
                }

            }

            // Draw Shortcut text if needed
            if (this.DrawShortcutText != "" && bIsOnMenu && !this.IsOnCustomizeDialog)
            {
                objStringFormat |= eTextFormat.HidePrefix | eTextFormat.Right;
                TextDrawing.DrawString(g, this.DrawShortcutText, objFont, textColor, rect, objStringFormat);
            }

            // If it has subitems draw the triangle to indicate that
            if ((this.SubItems.Count > 0 || this.PopupType == ePopupType.Container) && this.ShowSubItems)
            {
                if (bIsOnMenu)
                {
                    Point[] p = new Point[3];
                    p[0].X = itemRect.Left + itemRect.Width - 12;
                    p[0].Y = itemRect.Top + (itemRect.Height - 8) / 2;
                    p[1].X = p[0].X;
                    p[1].Y = p[0].Y + 8;
                    p[2].X = p[0].X + 4;
                    p[2].Y = p[0].Y + 4;
                    using (SolidBrush brush = new SolidBrush(textColor))
                        g.FillPolygon(brush, p);
                }
                else if (!m_SubItemsRect.IsEmpty)
                {
                    if (GetEnabled(pa.ContainerControl) && ((mouseOver || m_Checked) && !m_Expanded && m_HotTrackingStyle != eHotTrackingStyle.None && m_HotTrackingStyle != eHotTrackingStyle.Image))
                    {
                        if (m_Orientation == eOrientation.Horizontal)
                        {
                            using (Pen mypen = new Pen(pa.Colors.ItemHotBorder))
                                g.DrawLine(mypen/*SystemPens.Highlight*/, itemRect.Left + m_SubItemsRect.Left, itemRect.Top, itemRect.Left + m_SubItemsRect.Left, itemRect.Bottom - 1);
                        }
                        else
                        {
                            using (Pen mypen = new Pen(pa.Colors.ItemHotBorder))
                                g.DrawLine(mypen/*SystemPens.Highlight*/, itemRect.Left, itemRect.Top + m_SubItemsRect.Top, itemRect.Right - 2, itemRect.Top + m_SubItemsRect.Top);
                        }
                    }
                    Point[] p = new Point[3];
                    if (this.PopupSide == ePopupSide.Default)
                    {
                        if (m_Orientation == eOrientation.Horizontal)
                        {
                            p[0].X = itemRect.Left + m_SubItemsRect.Left + (m_SubItemsRect.Width - 5) / 2;
                            p[0].Y = itemRect.Top + (m_SubItemsRect.Height - 3) / 2 + 1;
                            p[1].X = p[0].X + 5;
                            p[1].Y = p[0].Y;
                            p[2].X = p[0].X + 2;
                            p[2].Y = p[0].Y + 3;
                        }
                        else
                        {
                            p[0].X = itemRect.Left + (m_SubItemsRect.Width - 3) / 2 + 1;
                            p[0].Y = itemRect.Top + m_SubItemsRect.Top + (m_SubItemsRect.Height - 5) / 2;
                            p[1].X = p[0].X;
                            p[1].Y = p[0].Y + 6;
                            p[2].X = p[0].X - 3;
                            p[2].Y = p[0].Y + 3;
                        }
                    }
                    else
                    {
                        switch (this.PopupSide)
                        {
                            case ePopupSide.Left:
                                {
                                    p[0].X = itemRect.Left + m_SubItemsRect.Left + m_SubItemsRect.Width / 2;
                                    p[0].Y = itemRect.Top + m_SubItemsRect.Height / 2 - 3;
                                    p[1].X = p[0].X;
                                    p[1].Y = p[0].Y + 6;
                                    p[2].X = p[0].X + 3;
                                    p[2].Y = p[0].Y + 3;
                                    break;
                                }
                            case ePopupSide.Right:
                                {
                                    p[0].X = itemRect.Left + m_SubItemsRect.Left + m_SubItemsRect.Width / 2 + 3;
                                    p[0].Y = itemRect.Top + m_SubItemsRect.Height / 2 - 3;
                                    p[1].X = p[0].X;
                                    p[1].Y = p[0].Y + 6;
                                    p[2].X = p[0].X - 3;
                                    p[2].Y = p[0].Y + 3;
                                    break;
                                }
                            case ePopupSide.Top:
                                {
                                    p[0].X = itemRect.Left + m_SubItemsRect.Left + (m_SubItemsRect.Width - 5) / 2;
                                    p[0].Y = itemRect.Top + (m_SubItemsRect.Height - 3) / 2 + 4;
                                    p[1].X = p[0].X + 6;
                                    p[1].Y = p[0].Y;
                                    p[2].X = p[0].X + 3;
                                    p[2].Y = p[0].Y - 4;
                                    break;
                                }
                            case ePopupSide.Bottom:
                                {
                                    p[0].X = itemRect.Left + m_SubItemsRect.Left + (m_SubItemsRect.Width - 5) / 2 + 1;
                                    p[0].Y = itemRect.Top + (m_SubItemsRect.Height - 3) / 2 + 1;
                                    p[1].X = p[0].X + 5;
                                    p[1].Y = p[0].Y;
                                    p[2].X = p[0].X + 2;
                                    p[2].Y = p[0].Y + 3;
                                    break;
                                }
                        }
                    }
                    if (GetEnabled(pa.ContainerControl))
                    {
                        using (SolidBrush mybrush = new SolidBrush(pa.Colors.ItemText))
                            g.FillPolygon(mybrush/*SystemBrushes.ControlText*/, p);
                    }
                    else
                    {
                        using (SolidBrush mybrush = new SolidBrush(pa.Colors.ItemDisabledText))
                            g.FillPolygon(mybrush/*SystemBrushes.ControlDark*/, p);
                    }
                }
            }

            if (this.Focused && this.DesignMode)
            {
                Rectangle r = itemRect;
                r.Inflate(-1, -1);
                DesignTime.DrawDesignTimeSelection(g, r, pa.Colors.ItemDesignTimeBorder);
            }

            if (objImage != null)
                objImage.Dispose();
        }
コード例 #43
0
		public static void PaintButton(ButtonItem button, ItemPaintArgs pa)
		{
			System.Drawing.Graphics g=pa.Graphics;
			ThemeToolbar theme=pa.ThemeToolbar;
			ThemeToolbarParts part=ThemeToolbarParts.Button;
			ThemeToolbarStates state=ThemeToolbarStates.Normal;
			Color textColor=ButtonItemPainterHelper.GetTextColor(button,pa);

			Rectangle rectImage=Rectangle.Empty;
			Rectangle itemRect=button.DisplayRectangle;
			
			Font font=null;
			CompositeImage image=button.GetImage();

			font=button.GetFont(pa, false);

			eTextFormat format= GetStringFormat(button, pa, image);

			bool bSplitButton=(button.SubItems.Count>0 || button.PopupType==ePopupType.Container) && button.ShowSubItems && !button.SubItemsRect.IsEmpty;

			if(bSplitButton)
				part=ThemeToolbarParts.SplitButton;

			// Calculate image position
			if(image!=null)
			{
				if(button.ImagePosition==eImagePosition.Top || button.ImagePosition==eImagePosition.Bottom)
					rectImage=new Rectangle(button.ImageDrawRect.X,button.ImageDrawRect.Y,itemRect.Width,button.ImageDrawRect.Height);
				else
					rectImage=new Rectangle(button.ImageDrawRect.X,button.ImageDrawRect.Y,button.ImageDrawRect.Width,button.ImageDrawRect.Height);

				rectImage.Offset(itemRect.Left,itemRect.Top);
				rectImage.Offset((rectImage.Width-button.ImageSize.Width)/2,(rectImage.Height-button.ImageSize.Height)/2);
				rectImage.Width=button.ImageSize.Width;
				rectImage.Height=button.ImageSize.Height;
			}

			// Set the state and text brush
			if(!ButtonItemPainter.IsItemEnabled(button, pa))
			{
				state=ThemeToolbarStates.Disabled;
			}
			else if(button.IsMouseDown)
			{
				state=ThemeToolbarStates.Pressed;
			}
			else if(button.IsMouseOver && button.Checked)
			{
				state=ThemeToolbarStates.HotChecked;
			}
			else if(button.IsMouseOver || button.Expanded)
			{
				state=ThemeToolbarStates.Hot;
			}
			else if(button.Checked)
			{
				state=ThemeToolbarStates.Checked;
			}
			
			Rectangle backRect=button.DisplayRectangle;
			if(button.HotTrackingStyle==eHotTrackingStyle.Image && image!=null)
			{
				backRect=rectImage;
				backRect.Inflate(3,3);
			}
			else if(bSplitButton)
			{
				backRect.Width=backRect.Width-button.SubItemsRect.Width;
			}

			// Draw Button Background
			if(button.HotTrackingStyle!=eHotTrackingStyle.None)
			{
				theme.DrawBackground(g,part,state,backRect);
			}

			// Draw Image
			if(image!=null && button.ButtonStyle!=eButtonStyle.TextOnlyAlways)
			{
				if(state==ThemeToolbarStates.Normal && button.HotTrackingStyle==eHotTrackingStyle.Color)
				{
					// Draw gray-scale image for this hover style...
					float[][] array = new float[5][];
					array[0] = new float[5] {0.2125f, 0.2125f, 0.2125f, 0, 0};
					array[1] = new float[5] {0.5f, 0.5f, 0.5f, 0, 0};
					array[2] = new float[5] {0.0361f, 0.0361f, 0.0361f, 0, 0};
					array[3] = new float[5] {0,       0,       0,       1, 0};
					array[4] = new float[5] {0.2f,    0.2f,    0.2f,    0, 1};
					System.Drawing.Imaging.ColorMatrix grayMatrix = new System.Drawing.Imaging.ColorMatrix(array);
					System.Drawing.Imaging.ImageAttributes att = new System.Drawing.Imaging.ImageAttributes();
					att.SetColorMatrix(grayMatrix);
					//g.DrawImage(image,rectImage,0,0,image.Width,image.Height,GraphicsUnit.Pixel,att);
					image.DrawImage(g,rectImage,0,0,image.Width,image.Height,GraphicsUnit.Pixel,att);
				}
				else if(state==ThemeToolbarStates.Normal && !image.IsIcon)
				{
					// Draw image little bit lighter, I decied to use gamma it is easy
					System.Drawing.Imaging.ImageAttributes lightImageAttr = new System.Drawing.Imaging.ImageAttributes();
					lightImageAttr.SetGamma(.7f,System.Drawing.Imaging.ColorAdjustType.Bitmap);
					//g.DrawImage(image,rectImage,0,0,image.Width,image.Height,GraphicsUnit.Pixel,lightImageAttr);
					image.DrawImage(g,rectImage,0,0,image.Width,image.Height,GraphicsUnit.Pixel,lightImageAttr);
				}
				else
				{
					image.DrawImage(g,rectImage);
				}
			}

			// Draw Text
			if(button.ButtonStyle==eButtonStyle.ImageAndText || button.ButtonStyle==eButtonStyle.TextOnlyAlways || image==null)
			{
				Rectangle rectText=button.TextDrawRect;
				if(button.ImagePosition==eImagePosition.Top || button.ImagePosition==eImagePosition.Bottom)
				{
					if(button.Orientation==eOrientation.Vertical)
					{
						rectText=new Rectangle(button.TextDrawRect.X,button.TextDrawRect.Y,button.TextDrawRect.Width,button.TextDrawRect.Height);
					}
					else
					{
						rectText=new Rectangle(button.TextDrawRect.X,button.TextDrawRect.Y,itemRect.Width,button.TextDrawRect.Height);
						if((button.SubItems.Count>0 || button.PopupType==ePopupType.Container) && button.ShowSubItems)
							rectText.Width-=10;
					}
					format|=eTextFormat.HorizontalCenter;
				}

				rectText.Offset(itemRect.Left,itemRect.Top);

				if(button.Orientation==eOrientation.Vertical)
				{
					g.RotateTransform(90);
					TextDrawing.DrawStringLegacy(g,ButtonItemPainter.GetDrawText(button.Text),font,textColor,new Rectangle(rectText.Top,-rectText.Right,rectText.Height,rectText.Width),format);
					g.ResetTransform();
				}
				else
				{
					if(rectText.Right>button.DisplayRectangle.Right)
						rectText.Width=button.DisplayRectangle.Right-rectText.Left;
					TextDrawing.DrawString(g,ButtonItemPainter.GetDrawText(button.Text),font,textColor,rectText,format);
					if(!button.DesignMode && button.Focused && !pa.IsOnMenu && !pa.IsOnMenuBar)
					{
						//SizeF szf=g.MeasureString(m_Text,font,rectText.Width,format);
						Rectangle r=rectText;
						//r.Width=(int)Math.Ceiling(szf.Width);
						//r.Height=(int)Math.Ceiling(szf.Height);
						//r.Inflate(1,1);
						System.Windows.Forms.ControlPaint.DrawFocusRectangle(g,r);
					}
				}				
			}

			// If it has subitems draw the triangle to indicate that
			if(bSplitButton)
			{
				part=ThemeToolbarParts.SplitButtonDropDown;
				
				if(!ButtonItemPainter.IsItemEnabled(button, pa))
					state=ThemeToolbarStates.Disabled;
				else
					state=ThemeToolbarStates.Normal;

				if(button.HotTrackingStyle!=eHotTrackingStyle.None && button.HotTrackingStyle!=eHotTrackingStyle.Image && ButtonItemPainter.IsItemEnabled(button, pa))
				{
					if(button.Expanded || button.IsMouseDown)
						state=ThemeToolbarStates.Pressed;
					else if(button.IsMouseOver && button.Checked)
						state=ThemeToolbarStates.HotChecked;
					else if(button.Checked)
						state=ThemeToolbarStates.Checked;
					else if(button.IsMouseOver)
						state=ThemeToolbarStates.Hot;
				}

                if (!button.AutoExpandOnClick)
                {
                    if (button.Orientation == eOrientation.Horizontal)
                    {
                        Rectangle r = button.SubItemsRect;
                        r.Offset(itemRect.X, itemRect.Y);
                        theme.DrawBackground(g, part, state, r);
                    }
                    else
                    {
                        Rectangle r = button.SubItemsRect;
                        r.Offset(itemRect.X, itemRect.Y);
                        theme.DrawBackground(g, part, state, r);
                    }
                }
			}

			if(button.Focused && button.DesignMode)
			{
				Rectangle r=itemRect;
				r.Inflate(-1,-1);
				DesignTime.DrawDesignTimeSelection(g,r,pa.Colors.ItemDesignTimeBorder);
			}

			if(image!=null)
				image.Dispose();
		}
コード例 #44
0
        public void SaveImagesAtLevel(int level)
        {
            try
            {
                var path = string.Format(Path.Combine(_rootTilesPath, level.ToString()));
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);                    
                }

                _map.Size = new Size(256, 256);
                _map.ZoomToExtents();
                
                // number images of title on a line
                var lineNumberImage = (int)(Math.Pow(2, level));
                _map.Zoom = _map.Zoom / lineNumberImage;
                
                // 1/2 length image in world
                var delta = _map.Center.X - _map.Envelope.MinX;
                
                // image size per tile ( in world )
                var imageWidth = _map.Envelope.MaxX - _map.Envelope.MinX;
                var imageHeight = imageWidth;

                // move center to left-up img ( left-bottom in pixel )          
                var centerX0 = _map.Center.X - (lineNumberImage * imageWidth) / 2 + delta;
                var centerY0 = _map.Center.Y + (lineNumberImage * imageHeight) / 2 - delta;

                var ia = new System.Drawing.Imaging.ImageAttributes();
                var cm = new System.Drawing.Imaging.ColorMatrix {Matrix33 = _opacity};
                ia.SetColorMatrix(cm, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap);

                // All tile columns
                var centerX = centerX0;
                for (var i = 0; i < lineNumberImage; i++, centerX = centerX + imageWidth)
                {
                    var colPath = Path.Combine(path, i.ToString());
                    if (!Directory.Exists(colPath))
                        Directory.CreateDirectory(colPath);

                    var centerY = centerY0;
                    for (var j = 0; j < lineNumberImage; j++, centerY = centerY - imageHeight)
                    {
                        _map.Center = new GeoAPI.Geometries.Coordinate(centerX, centerY);
                        using (var img = _map.GetMap())
                        {
                            using (var transImg = new System.Drawing.Bitmap(img.Width, img.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
                            {
                                using (var g = System.Drawing.Graphics.FromImage(transImg))
                                {
                                    g.DrawImage(img, 
                                        new[] { 
                                            new Point(0, 0), 
                                            new Point(transImg.Size.Width, 0), 
                                            new Point(0, transImg.Size.Height), 
                                            /*new Point(transImg.Size)*/ },
                                            new Rectangle(new Point(0, 0), img.Size), GraphicsUnit.Pixel, ia);
                                }
                                SaveImage(transImg, colPath, j, _typeImage);
                            }
                        }
                    }
                }
            }
            catch(Exception ex) {
                throw new Exception(ex.Message);
            }
        }
コード例 #45
0
ファイル: FormattedText.cs プロジェクト: gitMaxim/duality
        /// <summary>
        /// Renders a text to the specified target Image.
        /// </summary>
        /// <param name="text"></param>
        /// <param name="target"></param>
        public void RenderToBitmap(string text, System.Drawing.Image target, float x = 0.0f, float y = 0.0f, System.Drawing.Image icons = null)
        {
            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(target))
            {
                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                // Rendering
                int fontNum = this.fonts != null ? this.fonts.Length : 0;
                RenderState state = new RenderState(this);
                Element elem;
                while ((elem = state.NextElement()) != null)
                {
                    if (elem is TextElement && state.Font != null)
                    {
                        TextElement textElem = elem as TextElement;
                        state.Font.RenderToBitmap(
                            state.CurrentElemText,
                            target,
                            x + state.CurrentElemOffset.X,
                            y + state.CurrentElemOffset.Y + state.LineBaseLine - state.Font.BaseLine,
                            state.Color);
                    }
                    else if (elem is IconElement)
                    {
                        IconElement iconElem = elem as IconElement;
                        Icon icon = iconElem.IconIndex >= 0 && iconElem.IconIndex < this.icons.Length ? this.icons[iconElem.IconIndex] : new Icon();
                        Vector2 iconSize = icon.size;
                        Vector2 iconOffset = icon.offset;
                        Rect iconUvRect = icon.uvRect;
                        Vector2 dataCoord = iconUvRect.Pos * new Vector2(icons.Width, icons.Height);
                        Vector2 dataSize = iconUvRect.Size * new Vector2(icons.Width, icons.Height);

                        var attrib = new System.Drawing.Imaging.ImageAttributes();
                        attrib.SetColorMatrix(new System.Drawing.Imaging.ColorMatrix(new[] {
                            new[] {state.Color.R / 255.0f, 0, 0, 0},
                            new[] {0, state.Color.G / 255.0f, 0, 0},
                            new[] {0, 0, state.Color.B / 255.0f, 0},
                            new[] {0, 0, 0, state.Color.A / 255.0f} }));
                        g.DrawImage(icons,
                            new System.Drawing.Rectangle(
                                MathF.RoundToInt(x + state.CurrentElemOffset.X + iconOffset.X),
                                MathF.RoundToInt(y + state.CurrentElemOffset.Y + state.LineBaseLine - iconSize.Y + iconOffset.Y),
                                MathF.RoundToInt(iconSize.X),
                                MathF.RoundToInt(iconSize.Y)),
                            dataCoord.X, dataCoord.Y, dataSize.X, dataSize.Y,
                            System.Drawing.GraphicsUnit.Pixel,
                            attrib);
                    }
                }
            }
        }
コード例 #46
0
ファイル: DMEWeb_Image.cs プロジェクト: eopeter/dmelibrary
        /// <summary>
        /// 图片等比缩放
        /// </summary>
        /// <remarks>吴剑 2011-01-21</remarks>
        /// <param name="fromFile">原图Stream对象</param>
        /// <param name="savePath">缩略图存放地址</param>
        /// <param name="targetWidth">指定的最大宽度</param>
        /// <param name="targetHeight">指定的最大高度</param>
        /// <param name="watermarkText">水印文字(为""表示不使用水印)</param>
        /// <param name="watermarkImage">水印图片路径(为""表示不使用水印)</param>
        public static void ZoomAuto(System.IO.Stream fromFile, string savePath, System.Double targetWidth, System.Double targetHeight, string watermarkText, string watermarkImage)
        {
            //创建目录
            DME_Files.InitFolder(DME_Path.GetDirectoryName(savePath));

            //原始图片(获取原始图片创建对象,并使用流中嵌入的颜色管理信息)
            System.Drawing.Image initImage = System.Drawing.Image.FromStream(fromFile, true);

            //原图宽高均小于模版,不作处理,直接保存
            if (initImage.Width <= targetWidth && initImage.Height <= targetHeight)
            {
                //文字水印
                if (watermarkText != "")
                {
                    using (System.Drawing.Graphics gWater = System.Drawing.Graphics.FromImage(initImage))
                    {
                        System.Drawing.Font fontWater = new System.Drawing.Font("黑体", 12);
                        System.Drawing.Brush brushWater = new System.Drawing.SolidBrush(System.Drawing.Color.White);
                        gWater.DrawString(watermarkText, fontWater, brushWater, 10, 10);
                        gWater.Dispose();
                    }
                }

                //透明图片水印
                if (watermarkImage != "")
                {
                    if (DME_Files.FileExists(watermarkImage))
                    {
                        //获取水印图片
                        using (System.Drawing.Image wrImage = System.Drawing.Image.FromFile(watermarkImage))
                        {
                            //水印绘制条件:原始图片宽高均大于或等于水印图片
                            if (initImage.Width >= wrImage.Width && initImage.Height >= wrImage.Height)
                            {
                                System.Drawing.Graphics gWater = System.Drawing.Graphics.FromImage(initImage);

                                //透明属性
                                System.Drawing.Imaging.ImageAttributes imgAttributes = new System.Drawing.Imaging.ImageAttributes();
                                System.Drawing.Imaging.ColorMap colorMap = new System.Drawing.Imaging.ColorMap();
                                colorMap.OldColor = System.Drawing.Color.FromArgb(255, 0, 255, 0);
                                colorMap.NewColor = System.Drawing.Color.FromArgb(0, 0, 0, 0);
                                System.Drawing.Imaging.ColorMap[] remapTable = { colorMap };
                                imgAttributes.SetRemapTable(remapTable, System.Drawing.Imaging.ColorAdjustType.Bitmap);

                                float[][] colorMatrixElements = {
                                   new float[] {1.0f,  0.0f,  0.0f,  0.0f, 0.0f},
                                   new float[] {0.0f,  1.0f,  0.0f,  0.0f, 0.0f},
                                   new float[] {0.0f,  0.0f,  1.0f,  0.0f, 0.0f},
                                   new float[] {0.0f,  0.0f,  0.0f,  0.5f, 0.0f},//透明度:0.5
                                   new float[] {0.0f,  0.0f,  0.0f,  0.0f, 1.0f}
                                };

                                System.Drawing.Imaging.ColorMatrix wmColorMatrix = new System.Drawing.Imaging.ColorMatrix(colorMatrixElements);
                                imgAttributes.SetColorMatrix(wmColorMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap);
                                gWater.DrawImage(wrImage, new System.Drawing.Rectangle(initImage.Width - wrImage.Width, initImage.Height - wrImage.Height, wrImage.Width, wrImage.Height), 0, 0, wrImage.Width, wrImage.Height, System.Drawing.GraphicsUnit.Pixel, imgAttributes);

                                gWater.Dispose();
                            }
                            wrImage.Dispose();
                        }
                    }
                }

                //保存
                initImage.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            else
            {
                //缩略图宽、高计算
                double newWidth = initImage.Width;
                double newHeight = initImage.Height;

                //宽大于高或宽等于高(横图或正方)
                if (initImage.Width > initImage.Height || initImage.Width == initImage.Height)
                {
                    //如果宽大于模版
                    if (initImage.Width > targetWidth)
                    {
                        //宽按模版,高按比例缩放
                        newWidth = targetWidth;
                        newHeight = initImage.Height * (targetWidth / initImage.Width);
                    }
                }
                //高大于宽(竖图)
                else
                {
                    //如果高大于模版
                    if (initImage.Height > targetHeight)
                    {
                        //高按模版,宽按比例缩放
                        newHeight = targetHeight;
                        newWidth = initImage.Width * (targetHeight / initImage.Height);
                    }
                }

                //生成新图
                //新建一个bmp图片
                System.Drawing.Image newImage = new System.Drawing.Bitmap((int)newWidth, (int)newHeight);
                //新建一个画板
                System.Drawing.Graphics newG = System.Drawing.Graphics.FromImage(newImage);

                //设置质量
                newG.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                newG.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                //置背景色
                newG.Clear(System.Drawing.Color.White);
                //画图
                newG.DrawImage(initImage, new System.Drawing.Rectangle(0, 0, newImage.Width, newImage.Height), new System.Drawing.Rectangle(0, 0, initImage.Width, initImage.Height), System.Drawing.GraphicsUnit.Pixel);

                //文字水印
                if (watermarkText != "")
                {
                    using (System.Drawing.Graphics gWater = System.Drawing.Graphics.FromImage(newImage))
                    {
                        System.Drawing.Font fontWater = new System.Drawing.Font("宋体", 10);
                        System.Drawing.Brush brushWater = new System.Drawing.SolidBrush(System.Drawing.Color.White);
                        gWater.DrawString(watermarkText, fontWater, brushWater, 10, 10);
                        gWater.Dispose();
                    }
                }

                //透明图片水印
                if (watermarkImage != "")
                {
                    if (DME_Files.FileExists(watermarkImage))
                    {
                        //获取水印图片
                        using (System.Drawing.Image wrImage = System.Drawing.Image.FromFile(watermarkImage))
                        {
                            //水印绘制条件:原始图片宽高均大于或等于水印图片
                            if (newImage.Width >= wrImage.Width && newImage.Height >= wrImage.Height)
                            {
                                System.Drawing.Graphics gWater = System.Drawing.Graphics.FromImage(newImage);

                                //透明属性
                                System.Drawing.Imaging.ImageAttributes imgAttributes = new System.Drawing.Imaging.ImageAttributes();
                                System.Drawing.Imaging.ColorMap colorMap = new System.Drawing.Imaging.ColorMap();
                                colorMap.OldColor = System.Drawing.Color.FromArgb(255, 0, 255, 0);
                                colorMap.NewColor = System.Drawing.Color.FromArgb(0, 0, 0, 0);
                                System.Drawing.Imaging.ColorMap[] remapTable = { colorMap };
                                imgAttributes.SetRemapTable(remapTable, System.Drawing.Imaging.ColorAdjustType.Bitmap);

                                float[][] colorMatrixElements = {
                                   new float[] {1.0f,  0.0f,  0.0f,  0.0f, 0.0f},
                                   new float[] {0.0f,  1.0f,  0.0f,  0.0f, 0.0f},
                                   new float[] {0.0f,  0.0f,  1.0f,  0.0f, 0.0f},
                                   new float[] {0.0f,  0.0f,  0.0f,  0.5f, 0.0f},//透明度:0.5
                                   new float[] {0.0f,  0.0f,  0.0f,  0.0f, 1.0f}
                                };

                                System.Drawing.Imaging.ColorMatrix wmColorMatrix = new System.Drawing.Imaging.ColorMatrix(colorMatrixElements);
                                imgAttributes.SetColorMatrix(wmColorMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap);
                                gWater.DrawImage(wrImage, new System.Drawing.Rectangle(newImage.Width - wrImage.Width, newImage.Height - wrImage.Height, wrImage.Width, wrImage.Height), 0, 0, wrImage.Width, wrImage.Height, System.Drawing.GraphicsUnit.Pixel, imgAttributes);
                                gWater.Dispose();
                            }
                            wrImage.Dispose();
                        }
                    }
                }

                //保存缩略图
                newImage.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);

                //释放资源
                newG.Dispose();
                newImage.Dispose();
                initImage.Dispose();
            }
        }
コード例 #47
0
        private void PaintOffice(ItemPaintArgs pa)
        {
            System.Drawing.Graphics g = pa.Graphics;
            Rectangle rect = Rectangle.Empty;
            Rectangle itemRect = m_Rect;
            Rectangle rTmp = Rectangle.Empty;
            Color textColor = SystemColors.ControlText;
            Color color3d = SystemColors.Control;

            if (m_Parent is GenericItemContainer && !((GenericItemContainer)m_Parent).BackColor.IsEmpty)
                color3d = ((GenericItemContainer)m_Parent).BackColor;
            else if (m_Parent is SideBarPanelItem && !((SideBarPanelItem)m_Parent).BackgroundStyle.BackColor1.IsEmpty)
                color3d = ((SideBarPanelItem)m_Parent).BackgroundStyle.BackColor1.GetCompositeColor();

            if (m_MouseOver && !m_HotForeColor.IsEmpty)
                textColor = m_HotForeColor;
            else if (!m_ForeColor.IsEmpty)
                textColor = m_ForeColor;

            Font objFont = null;
            bool bIsOnMenu = pa.IsOnMenu;
            bool buttonX = pa.ContainerControl is ButtonX;
            //g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;
            //g.TextRenderingHint=System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            eTextFormat objStringFormat = pa.ButtonStringFormat;
            CompositeImage objImage = GetImage();

            if (m_Font != null)
                objFont = m_Font;
            else
                objFont = GetFont(pa, false);

            // Calculate image position
            if (objImage != null)
            {

                if (!bIsOnMenu && (m_ImagePosition == eImagePosition.Top || m_ImagePosition == eImagePosition.Bottom))
                    rect = new Rectangle(m_ImageDrawRect.X, m_ImageDrawRect.Y + 1, itemRect.Width, m_ImageDrawRect.Height);
                else
                    rect = m_ImageDrawRect; //new Rectangle(m_ImageDrawRect.X,m_ImageDrawRect.Y,m_ImageDrawRect.Width,m_ImageDrawRect.Height);

                rect.Offset(itemRect.Left, itemRect.Top);
                //if(m_ButtonType==eButtonType.StateButton)
                //	rect.Offset(STATEBUTTON_SPACING+(m_ImageSize.Width-STATEBUTTON_SPACING)/2+(rect.Width-m_Image.Width*2)/2,(rect.Height-m_Image.Height)/2);
                //else
                rect.Offset((rect.Width - this.ImageSize.Width) / 2, (rect.Height - this.ImageSize.Height) / 2);

                rect.Width = this.ImageSize.Width;
                rect.Height = this.ImageSize.Height;
            }

            // Draw background
            if (bIsOnMenu && !this.DesignMode && this.MenuVisibility == eMenuVisibility.VisibleIfRecentlyUsed && !this.RecentlyUsed)
                g.FillRectangle(new SolidBrush(ColorFunctions.RecentlyUsedOfficeBackColor()), m_Rect);
            else if (buttonX)
            {
                ButtonState state = ButtonState.Normal;
                if (m_MouseDown)
                    state = ButtonState.Pushed;
                else if (m_Checked || m_Expanded)
                    state = ButtonState.Checked;
                ControlPaint.DrawButton(g, itemRect, state);
            }
            //else
            //	g.FillRectangle(SystemBrushes.Control,m_Rect);

            if (GetEnabled(pa.ContainerControl) || this.DesignMode)
            {
                if (m_Expanded && !bIsOnMenu)
                {
                    // Office 2000 Style
                    g.FillRectangle(SystemBrushes.Control, itemRect);
                    //System.Windows.Forms.ControlPaint.DrawBorder3D(g,itemRect,System.Windows.Forms.Border3DStyle.SunkenOuter,System.Windows.Forms.Border3DSide.All);
                    BarFunctions.DrawBorder3D(g, itemRect, System.Windows.Forms.Border3DStyle.SunkenOuter, System.Windows.Forms.Border3DSide.All, color3d);
                }

                if ((m_MouseOver && m_HotTrackingStyle != eHotTrackingStyle.None) || m_Expanded || m_Checked && !this.IsOnCustomizeMenu && !this.IsOnCustomizeDialog)
                {
                    //if(m_ButtonType!=eButtonType.Label)
                    {
                        // Draw Mouse over marker
                        if (bIsOnMenu || this.IsOnCustomizeDialog)
                        {
                            if ((m_MouseOver && m_HotTrackingStyle != eHotTrackingStyle.None) || m_Expanded)
                            {
                                if (!(m_MouseOver && this.DesignMode) || this.IsOnCustomizeDialog)
                                    g.FillRectangle(SystemBrushes.Highlight, itemRect);
                            }
                        }
                        else
                        {
                            if (m_MouseDown || (m_Checked && !this.IsOnCustomizeMenu && !this.IsOnCustomizeDialog) || this.Expanded && (!this.ShowSubItems || this.IsOnMenuBar))
                            {
                                if (m_SubItemsRect.IsEmpty)
                                {
                                    if (!buttonX)
                                    {
                                        BarFunctions.DrawBorder3D(g, itemRect, System.Windows.Forms.Border3DStyle.SunkenOuter, System.Windows.Forms.Border3DSide.All, color3d);
                                        if (m_Checked && !m_MouseOver && !this.IsOnCustomizeMenu && !this.IsOnCustomizeDialog)
                                        {
                                            Rectangle r = itemRect; // Rectangle(itemRect.X,itemRect.Y,itemRect.Width,itemRect.Height);
                                            r.Inflate(-1, -1);
                                            g.FillRectangle(ColorFunctions.GetPushedBrush(this), r);
                                        }
                                    }
                                }
                                else
                                {
                                    if (!buttonX)
                                    {
                                        Rectangle r;
                                        if (m_Orientation == eOrientation.Horizontal)
                                            r = new Rectangle(itemRect.X, itemRect.Y, itemRect.Width - m_SubItemsRect.Width, itemRect.Height);
                                        else
                                            r = new Rectangle(itemRect.X, itemRect.Y, itemRect.Width, itemRect.Height - m_SubItemsRect.Height);
                                        //System.Windows.Forms.ControlPaint.DrawBorder3D(g,r,System.Windows.Forms.Border3DStyle.SunkenOuter,System.Windows.Forms.Border3DSide.All);
                                        BarFunctions.DrawBorder3D(g, r, System.Windows.Forms.Border3DStyle.SunkenOuter, System.Windows.Forms.Border3DSide.All, color3d);
                                        if (!m_MouseOver)
                                        {
                                            r.Inflate(-1, -1);
                                            g.FillRectangle(ColorFunctions.GetPushedBrush(this), r);
                                        }
                                    }
                                }
                            }
                            else if (!this.DesignMode)
                            {
                                if (m_SubItemsRect.IsEmpty)
                                {
                                    if (!buttonX)
                                        BarFunctions.DrawBorder3D(g, itemRect, System.Windows.Forms.Border3DStyle.RaisedInner, System.Windows.Forms.Border3DSide.All, color3d);
                                }
                                else
                                {
                                    Rectangle r;
                                    if (m_Orientation == eOrientation.Horizontal)
                                        r = new Rectangle(itemRect.X, itemRect.Y, itemRect.Width - m_SubItemsRect.Width, itemRect.Height);
                                    else
                                        r = new Rectangle(itemRect.X, itemRect.Y, itemRect.Width, itemRect.Height - m_SubItemsRect.Height);
                                    //System.Windows.Forms.ControlPaint.DrawBorder3D(g,r,System.Windows.Forms.Border3DStyle.RaisedInner,System.Windows.Forms.Border3DSide.All);
                                    BarFunctions.DrawBorder3D(g, r, System.Windows.Forms.Border3DStyle.RaisedInner, System.Windows.Forms.Border3DSide.All, color3d);
                                }
                            }

                        }

                        // TODO: Add support for Checked buttons etc...
                        if (objImage != null && m_ButtonStyle != eButtonStyle.TextOnlyAlways)
                        {
                            //if(m_ButtonType==eButtonType.StateButton)
                            //	rTmp=new Rectangle(m_ImageDrawRect.X,m_ImageDrawRect.Y,itemRect.Height,itemRect.Height);
                            //else
                            rTmp = new Rectangle(m_ImageDrawRect.X, m_ImageDrawRect.Y, m_ImageDrawRect.Width, itemRect.Height);
                            //if(m_ImagePosition==eImagePosition.Right)
                            //	rTmp.X=itemRect.Width-21-m_ImageDrawRect.Width;

                            rTmp.Offset(itemRect.Left, itemRect.Top);
                            if (bIsOnMenu)
                            {
                                if (m_Checked && !this.IsOnCustomizeMenu && !this.IsOnCustomizeDialog)
                                {
                                    //System.Windows.Forms.ControlPaint.DrawBorder3D(g,rTmp,System.Windows.Forms.Border3DStyle.SunkenOuter,System.Windows.Forms.Border3DSide.All);
                                    BarFunctions.DrawBorder3D(g, rTmp, System.Windows.Forms.Border3DStyle.SunkenOuter, System.Windows.Forms.Border3DSide.All, color3d);
                                    if (!m_MouseOver)
                                    {
                                        rTmp.Inflate(-1, -1);
                                        g.FillRectangle(ColorFunctions.GetPushedBrush(this), rTmp);
                                    }
                                    /*if(m_ButtonType==eButtonType.StateButton)
                                    {
                                        // Draw checker...
                                        Point[] pt=new Point[3];
                                        pt[0].X=rTmp.Left+(rTmp.Width-5)/2;
                                        pt[0].Y=rTmp.Top+(rTmp.Height-6)/2+3;
                                        pt[1].X=pt[0].X+2;
                                        pt[1].Y=pt[0].Y+2;
                                        pt[2].X=pt[1].X+4;
                                        pt[2].Y=pt[1].Y-4;
                                        g.DrawLines(SystemPens.ControlText,pt);
                                        pt[0].X++;
                                        //pt[0].Y
                                        pt[1].X++;
                                        //pt[1].Y;
                                        pt[2].X++;
                                        //pt[2].Y;
                                        g.DrawLines(SystemPens.ControlText,pt);
                                    }*/
                                }
                                else
                                {
                                    //System.Windows.Forms.ControlPaint.DrawBorder3D(g,rTmp,System.Windows.Forms.Border3DStyle.RaisedInner,System.Windows.Forms.Border3DSide.All);
                                    BarFunctions.DrawBorder3D(g, rTmp, System.Windows.Forms.Border3DStyle.RaisedInner, System.Windows.Forms.Border3DSide.All, color3d);
                                }
                                /*if(m_ButtonType==eButtonType.StateButton && m_MouseOver)
                                {
                                    rTmp=new Rectangle(rTmp.Right+STATEBUTTON_SPACING,rTmp.Top,m_ImageDrawRect.Width-rTmp.Width-STATEBUTTON_SPACING,itemRect.Height);
                                    System.Windows.Forms.ControlPaint.DrawBorder3D(g,rTmp,System.Windows.Forms.Border3DStyle.RaisedInner,System.Windows.Forms.Border3DSide.All);
                                }*/
                            }
                            else
                            {
                                if (m_MouseDown)
                                    rect.Offset(1, 1);
                            }
                            //g.DrawImage(objImage,rect,0,0,objImage.Width,objImage.Height,System.Drawing.GraphicsUnit.Pixel);
                            objImage.DrawImage(g, rect);
                        }
                        else if ((objImage == null || m_ButtonStyle == eButtonStyle.TextOnlyAlways) && m_Checked && !this.IsOnCustomizeMenu && !this.IsOnCustomizeDialog && bIsOnMenu)
                        {
                            // Draw checked box
                            rTmp = new Rectangle(m_ImageDrawRect.X, m_ImageDrawRect.Y, m_ImageDrawRect.Width, itemRect.Height);
                            rTmp.Offset(itemRect.Left, itemRect.Top);
                            DrawOfficeCheckBox(g, rTmp);
                        }
                    }
                    //else
                    //	g.FillRectangle(SystemBrushes.Highlight,itemRect);
                }
                else
                {
                    if (objImage != null && m_ButtonStyle != eButtonStyle.TextOnlyAlways)
                    {
                        if (m_HotTrackingStyle != eHotTrackingStyle.Color)
                        {
                            //g.DrawImage(objImage,rect,0,0,objImage.Width,objImage.Height,System.Drawing.GraphicsUnit.Pixel);
                            objImage.DrawImage(g, rect);
                        }
                        else if (m_HotTrackingStyle == eHotTrackingStyle.Color)
                        {
                            // Draw gray-scale image for this hover style...
                            float[][] array = new float[5][];
                            array[0] = new float[5] { 0.2125f, 0.2125f, 0.2125f, 0, 0 };
                            array[1] = new float[5] { 0.5f, 0.5f, 0.5f, 0, 0 };
                            array[2] = new float[5] { 0.0361f, 0.0361f, 0.0361f, 0, 0 };
                            array[3] = new float[5] { 0, 0, 0, 1, 0 };
                            array[4] = new float[5] { 0.2f, 0.2f, 0.2f, 0, 1 };
                            System.Drawing.Imaging.ColorMatrix grayMatrix = new System.Drawing.Imaging.ColorMatrix(array);
                            System.Drawing.Imaging.ImageAttributes att = new System.Drawing.Imaging.ImageAttributes();
                            att.SetColorMatrix(grayMatrix);
                            //g.DrawImage(objImage,rect,0,0,objImage.Width,objImage.Height,GraphicsUnit.Pixel,att);
                            objImage.DrawImage(g, rect, 0, 0, objImage.Width, objImage.Height, GraphicsUnit.Pixel, att);
                        }
                        //g.CompositingMode=System.Drawing.Drawing2D.CompositingMode.SourceCopy;
                    }
                }

                if (bIsOnMenu && this.IsOnCustomizeMenu && m_Visible && !this.SystemItem)
                {
                    Rectangle r = new Rectangle(m_Rect.Left, m_Rect.Top, m_Rect.Height, m_Rect.Height);
                    //r.Inflate(-1,-1);
                    DrawOfficeCheckBox(g, r);
                }
            }
            else
            {
                textColor = SystemColors.ControlDark;
                if (objImage != null && m_ButtonStyle != eButtonStyle.TextOnlyAlways)
                {
                    // Draw disabled image
                    //g.DrawImage(objImage,rect);
                    objImage.DrawImage(g, rect);
                }
            }

            // Draw menu item text
            if (bIsOnMenu || m_ButtonStyle != eButtonStyle.Default || objImage == null || (!bIsOnMenu && (m_ImagePosition == eImagePosition.Top || m_ImagePosition == eImagePosition.Bottom)))
            {
                if (bIsOnMenu)
                    rect = new Rectangle(m_TextDrawRect.X, m_TextDrawRect.Y, itemRect.Width - m_ImageDrawRect.Right - 24, m_TextDrawRect.Height);
                else
                {
                    rect = m_TextDrawRect;
                    if (m_ImagePosition == eImagePosition.Top || m_ImagePosition == eImagePosition.Bottom)
                    {
                        if (m_Orientation == eOrientation.Horizontal)
                            rect = new Rectangle(m_TextDrawRect.X, m_TextDrawRect.Y, itemRect.Width, m_TextDrawRect.Height);
                        if ((this.SubItems.Count > 0 || this.PopupType == ePopupType.Container) && m_Orientation == eOrientation.Horizontal && this.ShowSubItems)
                            rect.Width -= 12;

                        objStringFormat |= eTextFormat.HorizontalCenter;
                    }
                    //else
                    //rect=new Rectangle(m_TextDrawRect.X,m_TextDrawRect.Y,itemRect.Width-m_ImageDrawRect.Width,m_TextDrawRect.Height);
                }

                if (((m_MouseOver && m_HotTrackingStyle != eHotTrackingStyle.None) || m_Expanded) && bIsOnMenu && !this.DesignMode)
                    textColor = SystemColors.HighlightText;

                rect.Offset(itemRect.Left, itemRect.Top);

                if (!bIsOnMenu && (m_MouseDown || (this.Expanded && this.IsOnMenuBar)))
                    rect.Offset(1, 1);

                if (buttonX)
                {
                    objStringFormat |= eTextFormat.HorizontalCenter;
                    rect.Height--;
                }
                if (GetEnabled(pa.ContainerControl) || this.DesignMode)
                {
                    if (m_Orientation == eOrientation.Vertical && !bIsOnMenu)
                    {
                        g.RotateTransform(90);
                        TextDrawing.DrawStringLegacy(g, m_Text, objFont, textColor, new Rectangle(rect.Top, -rect.Right, rect.Height, rect.Width), objStringFormat);
                        g.ResetTransform();
                    }
                    else
                    {
                        TextDrawing.DrawString(g, m_Text, objFont, textColor, rect, objStringFormat);
                        if (!this.DesignMode && this.Focused && !bIsOnMenu && !pa.IsOnMenuBar)
                        {
                            //SizeF szf=g.MeasureString(m_Text,objFont,rect.Width,objStringFormat);
                            Rectangle r = rect;
                            //r.Width=(int)Math.Ceiling(szf.Width);
                            //r.Height=(int)Math.Ceiling(szf.Height);
                            //r.Inflate(1,1);
                            System.Windows.Forms.ControlPaint.DrawFocusRectangle(g, r);
                        }
                    }
                }
                else
                {
                    if (m_Orientation == eOrientation.Vertical && !bIsOnMenu)
                    {
                        g.RotateTransform(90);
                        System.Windows.Forms.ControlPaint.DrawStringDisabled(g, m_Text, objFont, SystemColors.Control, new Rectangle(rect.Top, -rect.Right, rect.Height, rect.Width), TextDrawing.GetStringFormat(objStringFormat));
                        g.ResetTransform();
                    }
                    else
                        System.Windows.Forms.ControlPaint.DrawStringDisabled(g, m_Text, objFont, SystemColors.Control, rect, TextDrawing.GetStringFormat(objStringFormat));
                }
            }

            // Draw Shortcut text if needed
            if (this.DrawShortcutText != "" && bIsOnMenu)
            {
                objStringFormat |= eTextFormat.HidePrefix | eTextFormat.Right;
                if (GetEnabled(pa.ContainerControl) || this.DesignMode)
                    TextDrawing.DrawString(g, this.DrawShortcutText, objFont, textColor, rect, objStringFormat);
                else
                    System.Windows.Forms.ControlPaint.DrawStringDisabled(g, this.DrawShortcutText, objFont, SystemColors.Control, rect, TextDrawing.GetStringFormat(objStringFormat));
            }

            // If it has subitems draw the triangle to indicate that
            if ((this.SubItems.Count > 0 || this.PopupType == ePopupType.Container) && this.ShowSubItems)
            {
                if (bIsOnMenu)
                {
                    Point[] p = new Point[3];
                    p[0].X = itemRect.Left + itemRect.Width - 12;
                    p[0].Y = itemRect.Top + (itemRect.Height - 8) / 2;
                    p[1].X = p[0].X;
                    p[1].Y = p[0].Y + 8;
                    p[2].X = p[0].X + 4;
                    p[2].Y = p[0].Y + 4;
                    using (SolidBrush brush = new SolidBrush(textColor))
                        g.FillPolygon(brush, p);
                }
                else if (!m_SubItemsRect.IsEmpty)
                {
                    if (m_MouseOver && !m_Expanded && m_HotTrackingStyle != eHotTrackingStyle.None)
                    {
                        Rectangle r = new Rectangle(m_SubItemsRect.X, m_SubItemsRect.Y, m_SubItemsRect.Width, m_SubItemsRect.Height);
                        r.Offset(itemRect.X, itemRect.Y);
                        //System.Windows.Forms.ControlPaint.DrawBorder3D(g,r,System.Windows.Forms.Border3DStyle.RaisedInner,System.Windows.Forms.Border3DSide.All);
                        BarFunctions.DrawBorder3D(g, r, System.Windows.Forms.Border3DStyle.RaisedInner, System.Windows.Forms.Border3DSide.All, color3d);
                    }
                    else if (m_Expanded)
                    {
                        Rectangle r = new Rectangle(m_SubItemsRect.X, m_SubItemsRect.Y, m_SubItemsRect.Width, m_SubItemsRect.Height);
                        r.Offset(itemRect.X, itemRect.Y);
                        //System.Windows.Forms.ControlPaint.DrawBorder3D(g,r,System.Windows.Forms.Border3DStyle.SunkenOuter,System.Windows.Forms.Border3DSide.All);
                        BarFunctions.DrawBorder3D(g, r, System.Windows.Forms.Border3DStyle.SunkenOuter, System.Windows.Forms.Border3DSide.All, color3d);
                    }
                    Point[] p = new Point[3];
                    if (m_Orientation == eOrientation.Horizontal)
                    {
                        p[0].X = itemRect.Left + m_SubItemsRect.Left + (m_SubItemsRect.Width - 5) / 2;
                        p[0].Y = itemRect.Top + (m_SubItemsRect.Height - 3) / 2 + 1;
                        p[1].X = p[0].X + 5;
                        p[1].Y = p[0].Y;
                        p[2].X = p[0].X + 2;
                        p[2].Y = p[0].Y + 3;
                    }
                    else
                    {
                        p[0].X = itemRect.Left + (m_SubItemsRect.Width - 3) / 2 + 1;
                        p[0].Y = itemRect.Top + m_SubItemsRect.Top + (m_SubItemsRect.Height - 5) / 2;
                        p[1].X = p[0].X;
                        p[1].Y = p[0].Y + 6;
                        p[2].X = p[0].X - 3;
                        p[2].Y = p[0].Y + 3;
                    }
                    g.FillPolygon(SystemBrushes.ControlText, p);
                }
            }

            if (this.Focused && this.DesignMode)
            {
                Rectangle r = itemRect;
                r.Inflate(-1, -1);
                g.DrawRectangle(new Pen(SystemColors.ControlText, 2), r);
            }

            if (objImage != null)
                objImage.Dispose();
        }
コード例 #48
0
 private void DrawForegroundFromButton(PaintEventArgs pevent)
 {
     if (_imageButton == null) {
         _imageButton = new Button();
         _imageButton.Parent = new TransparentControl();
         _imageButton.SuspendLayout();
         _imageButton.BackColor = Color.Transparent;
         _imageButton.FlatAppearance.BorderSize = 0;
         _imageButton.FlatStyle = FlatStyle.Flat;
     }
     else {
         _imageButton.SuspendLayout();
     }
     _imageButton.AutoEllipsis = AutoEllipsis;
     if (Enabled) {
         _imageButton.ForeColor = ForeColor;
     }
     else {
         _imageButton.ForeColor = Color.FromArgb((3 * ForeColor.R + _backColor.R) >> 2,
             (3 * ForeColor.G + _backColor.G) >> 2,
             (3 * ForeColor.B + _backColor.B) >> 2);
     }
     _imageButton.Font = Font;
     _imageButton.RightToLeft = RightToLeft;
     _imageButton.Image = Image;
     if (Image != null && !Enabled) {
         Size size = Image.Size;
         float[][] newColorMatrix = new float[5][];
         newColorMatrix[0] = new float[] { 0.2125f, 0.2125f, 0.2125f, 0f, 0f };
         newColorMatrix[1] = new float[] { 0.2577f, 0.2577f, 0.2577f, 0f, 0f };
         newColorMatrix[2] = new float[] { 0.0361f, 0.0361f, 0.0361f, 0f, 0f };
         float[] arr = new float[5];
         arr[3] = 1f;
         newColorMatrix[3] = arr;
         newColorMatrix[4] = new float[] { 0.38f, 0.38f, 0.38f, 0f, 1f };
         System.Drawing.Imaging.ColorMatrix matrix = new System.Drawing.Imaging.ColorMatrix(newColorMatrix);
         System.Drawing.Imaging.ImageAttributes disabledImageAttr = new System.Drawing.Imaging.ImageAttributes();
         disabledImageAttr.ClearColorKey();
         disabledImageAttr.SetColorMatrix(matrix);
         _imageButton.Image = new Bitmap(Image.Width, Image.Height);
         using (Graphics gr = Graphics.FromImage(_imageButton.Image)) {
             gr.DrawImage(Image, new Rectangle(0, 0, size.Width, size.Height), 0, 0, size.Width, size.Height, GraphicsUnit.Pixel, disabledImageAttr);
         }
     }
     _imageButton.ImageAlign = ImageAlign;
     _imageButton.ImageIndex = ImageIndex;
     _imageButton.ImageKey = ImageKey;
     _imageButton.ImageList = ImageList;
     _imageButton.Padding = Padding;
     _imageButton.Size = Size;
     _imageButton.Text = Text;
     _imageButton.TextAlign = TextAlign;
     _imageButton.TextImageRelation = TextImageRelation;
     _imageButton.UseCompatibleTextRendering = UseCompatibleTextRendering;
     _imageButton.UseMnemonic = UseMnemonic;
     _imageButton.ResumeLayout();
     InvokePaint(_imageButton, pevent);
     if (_imageButton.Image != null && _imageButton.Image != Image) {
         _imageButton.Image.Dispose();
         _imageButton.Image = null;
     }
 }
コード例 #49
0
        //────────────────────────────────────────
        /// <summary>
        /// 
        /// </summary>
        /// <param name="g"></param>
        /// <param name="isOnWindow"></param>
        /// <param name="memorySprite"></param>
        /// <param name="xBase">ベースX</param>
        /// <param name="yBase">ベースY</param>
        /// <param name="scale"></param>
        /// <param name="imgOpaque"></param>
        /// <param name="isImageGrid"></param>
        /// <param name="isInfodisplayVisible"></param>
        /// <param name="infodisplay"></param>
        public void Perform(
            Graphics g,
            bool isOnWindow,
            MemorySpriteImpl memorySprite,
            float xBase,
            float yBase,
            float scale,
            float imgOpaque,
            bool isImageGrid,
            bool isInfodisplayVisible,
            Usercontrolview_Infodisplay infodisplay
            )
        {
            // ビットマップ画像の不透明度を指定します。
            System.Drawing.Imaging.ImageAttributes ia;
            {
                System.Drawing.Imaging.ColorMatrix cm =
                    new System.Drawing.Imaging.ColorMatrix();
                cm.Matrix00 = 1;
                cm.Matrix11 = 1;
                cm.Matrix22 = 1;
                cm.Matrix33 = imgOpaque;//α値。0~1か?
                cm.Matrix44 = 1;

                //ImageAttributesオブジェクトの作成
                ia = new System.Drawing.Imaging.ImageAttributes();
                //ColorMatrixを設定する
                ia.SetColorMatrix(cm);
            }
            float dstX = 0;
            float dstY = 0;
            if (isOnWindow)
            {
                dstX += memorySprite.Lefttop.X;
                dstY += memorySprite.Lefttop.Y;
            }

            // 表示する画像の横幅、縦幅。
            float viWidth = (float)memorySprite.Bitmap.Width / memorySprite.CountcolumnResult;
            float viHeight = (float)memorySprite.Bitmap.Height / memorySprite.CountrowResult;

            // 横幅、縦幅の上限。
            if (memorySprite.WidthcellResult < viWidth)
            {
                viWidth = memorySprite.WidthcellResult;
            }

            if (memorySprite.HeightcellResult < viHeight)
            {
                viHeight = memorySprite.HeightcellResult;
            }

            // 枠を考慮しない画像サイズ
            Rectangle dstR = new Rectangle(
                (int)(dstX + xBase),
                (int)(dstY + yBase),
                (int)viWidth,
                (int)viHeight
                );
            Rectangle dstRScaled = new Rectangle(
                (int)(dstX + xBase),
                (int)(dstY + yBase),
                (int)(scale * viWidth),
                (int)(scale * viHeight)
                );

            // 太さ2pxの枠が収まるサイズ(Border Rectangle)
            int borderWidth = 2;
            Rectangle dstBr = new Rectangle(
                (int)dstX + borderWidth,
                (int)dstY + borderWidth,
                (int)viWidth - 2 * borderWidth,
                (int)viHeight - 2 * borderWidth);
            Rectangle dstBrScaled = new Rectangle(
                (int)dstX + borderWidth,
                (int)dstY + borderWidth,
                (int)(scale * viWidth) - 2 * borderWidth,
                (int)(scale * viHeight) - 2 * borderWidth);

            // 切り抜く位置。
            PointF srcL = memorySprite.GetCropXy();

            float gridX = memorySprite.GridLefttop.X;
            float gridY = memorySprite.GridLefttop.Y;

            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;//ドット絵のまま拡縮するように。しかし、この指定だと半ピクセル左上にずれるバグ。
            g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;//半ピクセル左上にずれるバグに対応。
            g.DrawImage(
                memorySprite.Bitmap,
                dstRScaled,
                srcL.X,
                srcL.Y,
                viWidth,
                viHeight,
                GraphicsUnit.Pixel,
                ia
                );

            // 枠線
            if (isImageGrid)
            {
                //
                // 枠線:影
                //
                // X,Yを、1ドット右下にずらします。
                dstRScaled.Offset(1, 1);
                // 最初の状態だと、右辺、下辺が外に1px出ています。
                // X,Yをずらした分と合わせて、縦幅、横幅を2ドット狭くします。
                dstRScaled.Width -= 2;
                dstRScaled.Height -= 2;
                g.DrawRectangle(Pens.Black, dstRScaled);
                //
                //
                dstRScaled.Offset(-1, -1);// 元の位置に戻します。
                dstRScaled.Width += 2;// 元のサイズに戻します。
                dstRScaled.Height += 2;

                //
                // 格子線は引かない。
                //

                // 枠線:緑
                // 最初から1ドット出ている分と、X,Yをずらした分と合わせて、
                // 縦幅、横幅を2ドット狭くします。
                dstRScaled.Width -= 2;
                dstRScaled.Height -= 2;
                g.DrawRectangle(Pens.Green, dstRScaled);
            }

            // 情報欄の描画
            if (isInfodisplayVisible)
            {
                int dy;
                if (isOnWindow)
                {
                    dy = 100;
                }
                else
                {
                    dy = 4;// 16;
                }
                infodisplay.Paint(g, isOnWindow, dy, scale);
            }
        }
コード例 #50
0
ファイル: Font.cs プロジェクト: KSLcom/duality
        /// <summary>
        /// Renders a text to the specified target Image.
        /// </summary>
        /// <param name="text"></param>
        /// <param name="target"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="clr"></param>
        public void RenderToBitmap(string text, Image target, float x, float y, ColorRgba clr)
        {
            Bitmap pixelData = this.pixelData.MainLayer.ToBitmap();
            using (Graphics g = Graphics.FromImage(target))
            {
                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                float curOffset = 0.0f;
                GlyphData glyphData;
                Rect uvRect;
                float glyphXOff;
                float glyphXAdv;
                var attrib = new System.Drawing.Imaging.ImageAttributes();
                attrib.SetColorMatrix(new System.Drawing.Imaging.ColorMatrix(new[] {
                    new[] {clr.R / 255.0f,					0.0f, 			0.0f, 			0.0f, 0.0f},
                    new[] {0.0f,			clr.G / 255.0f, 0.0f, 			0.0f, 			0.0f, 0.0f},
                    new[] {0.0f,			0.0f, 			clr.B / 255.0f, 0.0f, 			0.0f, 0.0f},
                    new[] {0.0f, 			0.0f, 			0.0f, 			clr.A / 255.0f, 0.0f, 0.0f},
                    new[] {0.0f, 			0.0f, 			0.0f, 			0.0f, 			0.0f, 0.0f},
                    new[] {0.0f, 			0.0f, 			0.0f, 			0.0f, 			0.0f, 0.0f} }));
                for (int i = 0; i < text.Length; i++)
                {
                    this.ProcessTextAdv(text, i, out glyphData, out uvRect, out glyphXAdv, out glyphXOff);
                    Vector2 dataCoord = uvRect.Pos * new Vector2(this.pixelData.Width, this.pixelData.Height) / this.texture.UVRatio;

                    if (clr == ColorRgba.White)
                    {
                        g.DrawImage(pixelData,
                            new Rectangle(MathF.RoundToInt(x + curOffset + glyphXOff), MathF.RoundToInt(y), glyphData.width, glyphData.height),
                            new Rectangle(MathF.RoundToInt(dataCoord.X), MathF.RoundToInt(dataCoord.Y), glyphData.width, glyphData.height),
                            GraphicsUnit.Pixel);
                    }
                    else
                    {
                        g.DrawImage(pixelData,
                            new Rectangle(MathF.RoundToInt(x + curOffset + glyphXOff), MathF.RoundToInt(y), glyphData.width, glyphData.height),
                            dataCoord.X, dataCoord.Y, glyphData.width, glyphData.height,
                            GraphicsUnit.Pixel,
                            attrib);
                    }

                    curOffset += glyphXAdv;
                }
            }
        }
コード例 #51
0
ファイル: VesselInfo.cs プロジェクト: BGog/GHud
        public VesselInfo(Device dev)
            : base(dev)
        {
            name = "Vessel";
            selectable = true;
            active = false;

            width = dev.width;
            height = dev.height;
            xoff = 0;
            yoff = 0;

            orbitinfo = new OrbitInfo(dev, "✈", System.Drawing.Color.FromArgb(0xee, 0xee, 0x00), System.Drawing.Color.FromArgb(0xaa, 0xaa, 0x44));
            target_orbitinfo = new OrbitInfo(dev, "+", System.Drawing.Color.LightBlue, System.Drawing.Color.MediumPurple);

            orbitgraph = new OrbitGraph(dev, System.Drawing.Color.Yellow, "✈");
            target_orbitgraph = new OrbitGraph(dev, System.Drawing.Color.LightBlue, "+");

            orbitgraph.companion_mod = orbitinfo;
            orbitinfo.companion_mod = orbitgraph;

            target_orbitinfo.is_target_type_module = true;
            target_orbitgraph.is_target_type_module = true;
            target_orbitinfo.companion_mod = target_orbitgraph;
            target_orbitgraph.companion_mod = target_orbitinfo;

            orbitinfo.Activate();
            active_top_mod = orbitinfo;
            orbitgraph.Activate();
            active_bottom_mod = orbitgraph;

            orbitinfo.modid = 1;
            target_orbitinfo.modid = 2;
            orbitgraph.modid = 3;
            target_orbitgraph.modid = 4;

            top_modules.Add(orbitinfo);
            top_modules.Add(target_orbitinfo);
            bottom_modules.Add(orbitgraph);
            bottom_modules.Add(target_orbitgraph);

            orbitinfo = new OrbitInfo(dev, "✈", System.Drawing.Color.FromArgb(0xee, 0xee, 0x00), System.Drawing.Color.FromArgb(0xaa, 0xaa, 0x44));
            target_orbitinfo = new OrbitInfo(dev, "+", System.Drawing.Color.LightBlue, System.Drawing.Color.MediumPurple);

            orbitgraph = new OrbitGraph(dev, System.Drawing.Color.Yellow, "✈");
            target_orbitgraph = new OrbitGraph(dev, System.Drawing.Color.LightBlue, "+");

            orbitgraph.companion_mod = orbitinfo;
            orbitinfo.companion_mod = orbitgraph;

            target_orbitinfo.is_target_type_module = true;
            target_orbitgraph.is_target_type_module = true;
            target_orbitinfo.companion_mod = target_orbitgraph;
            target_orbitgraph.companion_mod = target_orbitinfo;

            orbitinfo.modid = 1;
            target_orbitinfo.modid = 2;
            orbitgraph.modid = 3;
            target_orbitgraph.modid = 4;

            bottom_modules.Add(orbitinfo);
            bottom_modules.Add(target_orbitinfo);
            top_modules.Add(orbitgraph);
            top_modules.Add(target_orbitgraph);

            if(dev.use_backdrops)
                background = Image.FromFile("stars.gif");

            colmatrix = new System.Drawing.Imaging.ColorMatrix();
            colmatrix.Matrix33 = 0.7F;
            img_attr = new System.Drawing.Imaging.ImageAttributes();
            img_attr.SetColorMatrix(colmatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap);

            dev.ButtonUP += new Device.ButtonHandler(ButtonUp);
            dev.ButtonDOWN += new Device.ButtonHandler(ButtonDown);
        }
コード例 #52
0
ファイル: Form1.cs プロジェクト: priceLiu/ServerController
        //Paint background if selected
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            if ((!bTransparency & !bAero) | (bAero & (bAeroTexture|bAeroGradient)))
            {
                Rectangle BaseRectangle =
                    new Rectangle(0, 0, this.Width, this.Height);
                if (bGradient | (bAero&bAeroGradient))
                {

                    Color c1 = cColorB1, c2 = cColorB2;

                    if (bAero & bAeroGradient)
                    {
                        c1 = Color.FromArgb((byte)(fAeroTransparency * (float)255),c1);
                        c2 = Color.FromArgb((byte)(fAeroTransparency * (float)255),c2);
                    }
                    Brush Gradient_Brush =
                        new LinearGradientBrush(
                        BaseRectangle,
                        c1,
                        c2,
                        iGradAngle);

                    e.Graphics.FillRectangle(Gradient_Brush, BaseRectangle);
                }
                else
                {
                    Image ImageBack = null;

                        if (imageBackG != null)
                            ImageBack = imageBackG;
                        else
                            ImageBack = Properties.Resources.grey;

                        System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes();
                        float[][] colorMatrixElements = {
                           new float[] {fRedScale,  0,  0,  0, 0},        // red scaling factor
                           new float[] {0,  fGreenScale,  0,  0, 0},        // green scaling factor
                           new float[] {0,  0,  fBlueScale,  0, 0},        // blue scaling factor
                           new float[] {0,  0,  0,  1f, 0},        // alpha scaling factor of 1
                           new float[] {fRed, fGreen, fBlue, 0, 0}};    // three translations

                        System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(colorMatrixElements);

                        imageAttributes.SetColorMatrix(
                           colorMatrix,
                           System.Drawing.Imaging.ColorMatrixFlag.Default,
                           System.Drawing.Imaging.ColorAdjustType.Bitmap);

                        if(bAero & bAeroTexture)
                            ImageBack = ChangeImageOpacity(ImageBack, fAeroTransparency);

                        int width = ImageBack.Width;
                        int height = ImageBack.Height;

                        if (width > this.Width)
                        {
                            ImageBack.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
                            ImageBack.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
                            height = (height * this.Width) / width;
                            width = this.Width;
                            ImageBack = ImageBack.GetThumbnailImage(width, height, null, IntPtr.Zero);

                        }
                         if (bBGImageFill)
                            e.Graphics.DrawImage(
                               ImageBack,
                               BaseRectangle,
                               0, 0,        // upper-left corner of source rectangle
                               width,       // width of source rectangle
                               height,      // height of source rectangle
                               GraphicsUnit.Pixel,
                               imageAttributes);
                        else
                        {
                            imageAttributes.SetWrapMode(System.Drawing.Drawing2D.WrapMode.Tile);
                            Rectangle brushRect = new Rectangle(0, 0, width, height);
                            TextureBrush tBrush = new TextureBrush(ImageBack, brushRect, imageAttributes);
                            e.Graphics.FillRectangle(tBrush, BaseRectangle);
                            tBrush.Dispose();
                        }
                        ImageBack = null;
                    //}
                   // e.Graphics.DrawImage(ImageBack, BaseRectangle);
                }
            }

            //else
            //{
            //    Image ImageBack = null;
            //    Rectangle BaseRectangle =
            //        new Rectangle(0, 0, this.Width, this.Height);

            //    if (imageBackG != null)
            //        ImageBack = imageBackG;
            //    else
            //        ImageBack = Properties.Resources.grey;

            //    ImageBack = ChangeImageOpacity(ImageBack, fAeroTransparency);

            //    int width = ImageBack.Width;
            //    int height = ImageBack.Height;

            //    if (width > this.Width)
            //    {
            //        ImageBack.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
            //        ImageBack.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
            //        height = (height * this.Width) / width;
            //        width = this.Width;
            //        ImageBack = ImageBack.GetThumbnailImage(width, height, null, IntPtr.Zero);

            //    }
            //    System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes();
            //    if (bBGImageFill)
            //        e.Graphics.DrawImage(
            //           ImageBack,
            //           BaseRectangle,
            //           0, 0,        // upper-left corner of source rectangle
            //           width,       // width of source rectangle
            //           height,      // height of source rectangle
            //           GraphicsUnit.Pixel,
            //           imageAttributes);
            //    else
            //    {
            //        imageAttributes.SetWrapMode(System.Drawing.Drawing2D.WrapMode.Tile);
            //        Rectangle brushRect = new Rectangle(0, 0, width, height);
            //        TextureBrush tBrush = new TextureBrush(ImageBack, brushRect, imageAttributes);
            //        e.Graphics.FillRectangle(tBrush, BaseRectangle);
            //        tBrush.Dispose();
            //    }

            //    ImageBack = null;
            //    //}
            //    // e.Graphics.DrawImage(ImageBack, BaseRectangle);
            //}
        }
コード例 #53
0
		public IconImage(Image source)
		{
			this.sourceImage = source;

			// Generate specific images
			var imgAttribs = new System.Drawing.Imaging.ImageAttributes();
			System.Drawing.Imaging.ColorMatrix colorMatrix = null;
			{
				colorMatrix = new System.Drawing.Imaging.ColorMatrix(new float[][] {
					new float[] {1.0f, 0.0f, 0.0f, 0.0f, 0.0f},
					new float[] {0.0f, 1.0f, 0.0f, 0.0f, 0.0f},
					new float[] {0.0f, 0.0f, 1.0f, 0.0f, 0.0f},
					new float[] {0.0f, 0.0f, 0.0f, 0.65f, 0.0f},
					new float[] {0.0f, 0.0f, 0.0f, 0.0f, 1.0f}});
				imgAttribs.SetColorMatrix(colorMatrix);
				this.images[0] = new Bitmap(source.Width, source.Height);
				using (Graphics g = Graphics.FromImage(this.images[0]))
				{
					g.DrawImage(source, 
						new Rectangle(Point.Empty, source.Size), 
						0, 0, source.Width, source.Height, GraphicsUnit.Pixel, 
						imgAttribs);
				}
			}
			{
				colorMatrix = new System.Drawing.Imaging.ColorMatrix(new float[][] {
					new float[] {1.0f, 0.0f, 0.0f, 0.0f, 0.0f},
					new float[] {0.0f, 1.0f, 0.0f, 0.0f, 0.0f},
					new float[] {0.0f, 0.0f, 1.0f, 0.0f, 0.0f},
					new float[] {0.0f, 0.0f, 0.0f, 1.0f, 0.0f},
					new float[] {0.0f, 0.0f, 0.0f, 0.0f, 1.0f}});
				imgAttribs.SetColorMatrix(colorMatrix);
				this.images[1] = new Bitmap(source.Width, source.Height);
				using (Graphics g = Graphics.FromImage(this.images[1]))
				{
					g.DrawImage(source, 
						new Rectangle(Point.Empty, source.Size), 
						0, 0, source.Width, source.Height, GraphicsUnit.Pixel, 
						imgAttribs);
				}
			}
			{
				colorMatrix = new System.Drawing.Imaging.ColorMatrix(new float[][] {
					new float[] {1.3f, 0.0f, 0.0f, 0.0f, 0.0f},
					new float[] {0.0f, 1.3f, 0.0f, 0.0f, 0.0f},
					new float[] {0.0f, 0.0f, 1.3f, 0.0f, 0.0f},
					new float[] {0.0f, 0.0f, 0.0f, 1.0f, 0.0f},
					new float[] {0.0f, 0.0f, 0.0f, 0.0f, 1.0f}});
				imgAttribs.SetColorMatrix(colorMatrix);
				this.images[2] = new Bitmap(source.Width, source.Height);
				using (Graphics g = Graphics.FromImage(this.images[2]))
				{
					g.DrawImage(source, 
						new Rectangle(Point.Empty, source.Size), 
						0, 0, source.Width, source.Height, GraphicsUnit.Pixel, 
						imgAttribs);
				}
			}
			{
				colorMatrix = new System.Drawing.Imaging.ColorMatrix(new float[][] {
					new float[] {0.34f, 0.34f, 0.34f, 0.0f, 0.0f},
					new float[] {0.34f, 0.34f, 0.34f, 0.0f, 0.0f},
					new float[] {0.34f, 0.34f, 0.34f, 0.0f, 0.0f},
					new float[] {0.0f, 0.0f, 0.0f, 0.5f, 0.0f},
					new float[] {0.0f, 0.0f, 0.0f, 0.0f, 1.0f}});
				imgAttribs.SetColorMatrix(colorMatrix);
				this.images[3] = new Bitmap(source.Width, source.Height);
				using (Graphics g = Graphics.FromImage(this.images[3]))
				{
					g.DrawImage(source, 
						new Rectangle(Point.Empty, source.Size), 
						0, 0, source.Width, source.Height, GraphicsUnit.Pixel, 
						imgAttribs);
				}
			}
		}
コード例 #54
0
ファイル: PlayingState.cs プロジェクト: mrsheen/bbot
        // Scan the gem Board and capture a coloured pixel from each cell
        public bool ScanGrid()
        {
            bool bMatchedAllPieces = true;
            int unmatchedCount = 0;

            Color[,] pieceColors = new Color[8, 8];
            List<double> scores = new List<double>();

            const int CellExtractionFactor = 8; // 8ths, so skip first 5 px

            int top = CellSize / CellExtractionFactor;//topOffset;
            int left = CellSize / CellExtractionFactor; //leftOffset;

            string workingPath = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), DateTime.Now.ToString("hhmm"));
            //System.IO.Directory.CreateDirectory(workingPath+"known");
            //System.IO.Directory.CreateDirectory(workingPath + "unknown");

            // Mask out board
            Bitmap bmpMask = GetBitmap("board.mask", bmpBoard.Size, bmpBoard.PixelFormat);
            if (bmpMask != null)
            {
                Subtract subFilter = new Subtract(bmpMask);

                if (subFilter != null)
                    subFilter.ApplyInPlace(bmpBoard);

                Bitmap bmpRenderedBoard;
                if (game.DebugMode)
                {
                    bmpRenderedBoard = bmpBoard.Clone(new Rectangle(0, 0, bmpBoard.Width, bmpBoard.Height), bmpBoard.PixelFormat);

                    using (Graphics g = Graphics.FromImage(bmpRenderedBoard))
                    {
                        System.Drawing.Imaging.ColorMatrix cm = new System.Drawing.Imaging.ColorMatrix();
                        cm.Matrix00 = cm.Matrix11 = cm.Matrix22 = cm.Matrix44 = 1;
                        cm.Matrix43 = 1.0F;

                        System.Drawing.Imaging.ImageAttributes ia = new System.Drawing.Imaging.ImageAttributes();

                        ia.SetColorMatrix(cm);

                        g.DrawImage(bmpBoard, new Rectangle(0, 0, bmpBoard.Width, bmpBoard.Height), 0, 0, bmpBoard.Width, bmpBoard.Height, GraphicsUnit.Pixel, ia);
                    }
                }
            }

            // Across
            for (int x = 0; x < GridSize; x++)
            {
                // Down
                for (int y = 0; y < GridSize; y++)
                {
                    int boxLeft = left + (CellSize * x);
                    int boxTop = top + (CellSize * y);

                    // Get image of current gem
                    Rectangle rect = new Rectangle(boxLeft, boxTop, CellSize - 2 * (CellSize / CellExtractionFactor), CellSize - 2 * (CellSize / CellExtractionFactor));
                    Bitmap cropped = bmpBoard.Clone(rect, bmpBoard.PixelFormat);

                    ImageStatistics stats = new ImageStatistics(cropped);

                    // Capture a colour from this gem
                    Gem PieceColor = new Gem { Name = GemColor.None, Modifiers = GemModifier.None, Color = Color.FromArgb(255, (int)stats.Red.Mean, (int)stats.Green.Mean, (int)stats.Blue.Mean) };

                    // Calculate best score
                    double bestScore = 255*3; // what should this be set to?
                    double curScore = 0;

                    foreach (Gem gem in listGemColorStats)
                    {

                        curScore = Math.Pow(gem.Color.R-stats.Red.Mean, 2)
                                 + Math.Pow(gem.Color.G-stats.Green.Mean, 2)
                                 + Math.Pow(gem.Color.B-stats.Blue.Mean, 2);

                        if (curScore < bestScore)
                        {
                            PieceColor = gem;
                            bestScore = curScore;

                        }
                    }
                    scores.Add(bestScore);
                    // Store it in the Board matrix at the correct position
                    Board[x + 3, y + 3] = PieceColor;

                    Color newColor = Color.FromArgb(255,(int)stats.Red.Mean, (int)stats.Green.Mean, (int)stats.Blue.Mean);
                    pieceColors[x, y] = newColor;

                    if (game.DebugMode)
                    {
                        if (PieceColor.Name == GemColor.None || PieceColor.Modifiers == GemModifier.Background)
                        {
                            unmatchedCount++;
                            bMatchedAllPieces = false; // Didn't match one of the pieces, break on this
                            if ((DateTime.Now - backgroundMatchTimestamp).Seconds > 5)
                            {
                                System.IO.Directory.CreateDirectory(workingPath);

                                string colorName = string.Format("_{0}_{1}_{2}_", (int)newColor.R, (int)newColor.G, (int)newColor.B);
                                string gemName = string.Format("{0}.{1}", PieceColor.Name, PieceColor.Modifiers);
                                string basePath = System.IO.Path.Combine(workingPath, gemName);

                                string thisPath = string.Format("{0}{1}.bmp", basePath, colorName);

                                cropped.Save(thisPath);
                                game.Debug(String.Format("Written out unknown gamepiece {0},{1}", x,y));

                                //System.Diagnostics.Debugger.Break();
                            }

                        }

                    }

                    if (!listGemColorStats.Contains(PieceColor))
                    {

                        //listGemColorStats.Add(PieceColor, Color.FromArgb( stats.Red.Mean, stats.Green.Mean, stats.Blue.Mean });

                    }
                    /*
                    if (debugMode)
                    {
                        if (!knownColors.Contains(PieceColor))
                        {
                            string currentFilePath = Path.Combine(workingPath, string.Format("{0}.bmp",knownColors.Count));

                            using (FileStream fs = new FileStream(currentFilePath, FileMode.Create, FileAccess.Write))
                            {
                                cropped.Save(fs, System.Drawing.Imaging.ImageFormat.Bmp);
                            }
                            debugConsole.AppendText("Saved color " + PieceColor + " to file " + currentFilePath + System.Environment.NewLine);
                            knownColors.Add(PieceColor);
                        }

                    }*/
                }
            }
            if (bMatchedAllPieces)
                backgroundMatchTimestamp = DateTime.Now;

            return bMatchedAllPieces && unmatchedCount < 3;

            // Build known averages

            //RED
            /*
             *
             *
             * 0,0 0,2 0,5 0,6
             * 1,4 1,6
             * 3,2
             * 5,2
             * 6,7
             */
            /*
            List<Tuple<int,int>> redPairs = new List<Tuple<int,int>>();

            redPairs.Add(new Tuple<int,int>(0,0));
            redPairs.Add(new Tuple<int, int>(0, 2));
            redPairs.Add(new Tuple<int, int>(0, 5));
            redPairs.Add(new Tuple<int, int>(0, 6));
            redPairs.Add(new Tuple<int, int>(1, 3));
            redPairs.Add(new Tuple<int, int>(1, 5));
            redPairs.Add(new Tuple<int, int>(3, 2));
            redPairs.Add(new Tuple<int, int>(5, 2));
            redPairs.Add(new Tuple<int,int>(6,7));

            //BLUE
            /*
             *
             *
             * 1,1 1,2
             * 2,6 2,7
             * 3,6
             * 4,7
             * 5,0 5,3 5,6
             * 6,5 6,6
             * 7,3 7,5
             */
            /*
            List<Tuple<int, int>> bluePairs = new List<Tuple<int, int>>();

            bluePairs.Add(new Tuple<int, int>(1, 1));
            bluePairs.Add(new Tuple<int, int>(1, 2));
            bluePairs.Add(new Tuple<int, int>(2, 6));
            bluePairs.Add(new Tuple<int, int>(2, 7));
            bluePairs.Add(new Tuple<int, int>(3, 6));
            bluePairs.Add(new Tuple<int, int>(4, 7));
            bluePairs.Add(new Tuple<int, int>(5, 0));
            bluePairs.Add(new Tuple<int, int>(5, 3));
            bluePairs.Add(new Tuple<int, int>(5, 6));
            bluePairs.Add(new Tuple<int, int>(6, 5));
            bluePairs.Add(new Tuple<int, int>(6, 6));
            bluePairs.Add(new Tuple<int, int>(7, 3));
            bluePairs.Add(new Tuple<int, int>(7, 5));
            */

            //GREEN
            /*
             *
             *
             * 0,7
             * 3,1 3,5
             * 4,5
             * 6,4
             * 7,1
             */
            /*
            List<Tuple<int, int>> greenPairs = new List<Tuple<int, int>>();

            greenPairs.Add(new Tuple<int, int>(0, 7));
            greenPairs.Add(new Tuple<int, int>(3, 1));
            greenPairs.Add(new Tuple<int, int>(3, 5));
            greenPairs.Add(new Tuple<int, int>(4, 5));
            greenPairs.Add(new Tuple<int, int>(6, 4));
            greenPairs.Add(new Tuple<int, int>(7, 1));

            */
            //YELLOW
            /*
             * 0,3
             * 1,7
             * 2,1 2,3 2,4
             * 4,0
             * 5,5
             * 6,2
             * 7,6 7,7
             */
            /*
            List<Tuple<int, int>> yellowPairs = new List<Tuple<int, int>>();

            yellowPairs.Add(new Tuple<int, int>(0, 3));
            yellowPairs.Add(new Tuple<int, int>(1, 7));
            yellowPairs.Add(new Tuple<int, int>(2, 1));
            yellowPairs.Add(new Tuple<int, int>(2, 3));
            yellowPairs.Add(new Tuple<int, int>(2, 4));
            yellowPairs.Add(new Tuple<int, int>(4, 0));
            yellowPairs.Add(new Tuple<int, int>(5, 5));
            yellowPairs.Add(new Tuple<int, int>(6, 2));
            yellowPairs.Add(new Tuple<int, int>(7, 6));
            yellowPairs.Add(new Tuple<int, int>(7, 7));
            */

            //PURPLE
            /*
             * 1,0 1,4 1,6
             * 2,0
             * 4,2 4,6
             * 7,0 7,2
             */
            /*
            List<Tuple<int, int>> purplePairs = new List<Tuple<int, int>>();

            purplePairs.Add(new Tuple<int, int>(1, 0));
            purplePairs.Add(new Tuple<int, int>(1, 4));
            purplePairs.Add(new Tuple<int, int>(1, 6));
            purplePairs.Add(new Tuple<int, int>(2,0));
            purplePairs.Add(new Tuple<int, int>(4, 2));
            purplePairs.Add(new Tuple<int, int>(4, 6));
            purplePairs.Add(new Tuple<int, int>(7, 0));
            purplePairs.Add(new Tuple<int, int>(7, 2));
            */
            //WHITE
            /*
             * 0,1
             * 2,2
             * 3,3 3,4
             * 6,1 6,3
             * 7,4
             */
            /*
            List<Tuple<int, int>> whitePairs = new List<Tuple<int, int>>();

            whitePairs.Add(new Tuple<int, int>(0, 1));
            whitePairs.Add(new Tuple<int, int>(2, 2));
            whitePairs.Add(new Tuple<int, int>(3, 3));
            whitePairs.Add(new Tuple<int, int>(3, 4));
            whitePairs.Add(new Tuple<int, int>(6, 1));
            whitePairs.Add(new Tuple<int, int>(6, 3));
            whitePairs.Add(new Tuple<int, int>(7, 4));
            */
            //ORANGE
            /*
             * 0,4
             * 2,5
             * 3,0 3,7
             * 4,1 4,3 4,4
             * 5,1 5,4
             * 6,0
             */
            /*
            List<Tuple<int, int>> orangePairs = new List<Tuple<int, int>>();

            orangePairs.Add(new Tuple<int, int>(0, 4));
            orangePairs.Add(new Tuple<int, int>(2, 5));
            orangePairs.Add(new Tuple<int, int>(3, 0));
            orangePairs.Add(new Tuple<int, int>(3, 7));
            orangePairs.Add(new Tuple<int, int>(4, 1));
            orangePairs.Add(new Tuple<int, int>(4, 3));
            orangePairs.Add(new Tuple<int, int>(4, 4));
            orangePairs.Add(new Tuple<int, int>(5, 1));
            orangePairs.Add(new Tuple<int, int>(5, 4));
            orangePairs.Add(new Tuple<int, int>(6, 0));

            double rMean = 0;

            double gMean = 0;

            double bMean = 0;

            foreach (Tuple<int, int> pair in purplePairs)
            {
                rMean += pieceColors[pair.Item1,pair.Item2].R;

                gMean += pieceColors[pair.Item1, pair.Item2].G;

                bMean += pieceColors[pair.Item1, pair.Item2].B;
            }

            rMean = rMean / purplePairs.Count;
            gMean = gMean / purplePairs.Count;
            bMean = bMean / purplePairs.Count;
            listGemColorStats.Clear();
            listGemColorStats.Add(Color.Blue, Color.FromArgb( rMean, gMean, bMean });
            */
        }
コード例 #55
0
ファイル: Form2.cs プロジェクト: priceLiu/ServerController
        private void pBox_Paint(object sender, PaintEventArgs e)
        {
            lRed.Text = fRed.ToString();
            lGreen.Text = fGreen.ToString();
            lBlue.Text = fBlue.ToString();
            lRedScale.Text = fRedScale.ToString();
            lGreenScale.Text = fGreenScale.ToString();
            lBlueScale.Text = fBlueScale.ToString();

            Rectangle BaseRectangle =
                new Rectangle(0, 0, pBox.Width, pBox.Height);
            Image ImageBack = null;
            if (imageBackG == null)
            {
                ImageBack = Properties.Resources.grey;

            }
            else
            {
                ImageBack = imageBackG;
            }
            System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes();
            float[][] colorMatrixElements = {
                           new float[] {fRedScale,  0,  0,  0, 0},        // red scaling factor
                           new float[] {0,  fGreenScale,  0,  0, 0},        // green scaling factor
                           new float[] {0,  0,  fBlueScale,  0, 0},        // blue scaling factor
                           new float[] {0,  0,  0,  1, 0},        // alpha scaling factor of 1
                           new float[] {fRed, fGreen, fBlue, 0, 1}};    //translations

            System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(colorMatrixElements);

            imageAttributes.SetColorMatrix(
               colorMatrix,
               System.Drawing.Imaging.ColorMatrixFlag.Default,
               System.Drawing.Imaging.ColorAdjustType.Bitmap);

            int width = ImageBack.Width;
            int height = ImageBack.Height;

            // what to do when pic is larger than picture box...? I decided to scale it down to picbox width

            //if (height > pBox.Height)
            //{
            //    ImageBack.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
            //    ImageBack.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
            //    width = (width * pBox.Height) / height;
            //    height = pBox.Height;
            //    ImageBack = ImageBack.GetThumbnailImage(width, height, null, IntPtr.Zero);

            //}
            if (width > pBox.Width)
            {
                ImageBack.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
                ImageBack.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
                height = (height * pBox.Width) / width;
                width = pBox.Width;
                ImageBack = ImageBack.GetThumbnailImage(width, height, null, IntPtr.Zero);

            }
            if (bBGIFill)
                e.Graphics.DrawImage(
                   ImageBack,
                   BaseRectangle,
                   0, 0,        // upper-left corner of source rectangle
                   width,       // width of source rectangle
                   height,      // height of source rectangle
                   GraphicsUnit.Pixel,
                   imageAttributes);
            else
            {
                imageAttributes.SetWrapMode(System.Drawing.Drawing2D.WrapMode.Tile);
                Rectangle brushRect = new Rectangle(0, 0, width, height);
                TextureBrush tBrush = new TextureBrush(ImageBack, brushRect, imageAttributes);
                e.Graphics.FillRectangle(tBrush, BaseRectangle);
                tBrush.Dispose();
            }
               // ImageBack.Dispose();
        }
コード例 #56
0
		protected override void PaintControlBackground(ItemPaintArgs pa)
		{
            bool mouseOver = m_MouseOver;
            bool fade = m_FadeImageState!=null;

            if (fade)
                mouseOver = false;
            GraphicsPath insideClip = null;
            ElementStyle backStyle = GetBackgroundStyle();
            bool disposeBackStyle = fade;
            try
            {
                if (backStyle != null)
                {
                    Rectangle r = GetBackgroundRectangle();
                    pa.Graphics.SetClip(r, CombineMode.Replace);
                    ElementStyle mouseOverStyle = GetBackgroundMouseOverStyle();
                    if (mouseOver && backStyle != null && mouseOverStyle != null && mouseOverStyle.Custom)
                    {
                        backStyle = backStyle.Copy();
                        disposeBackStyle = true;
                        backStyle.ApplyStyle(mouseOverStyle);
                    }

                    ElementStyleDisplayInfo displayInfo = new ElementStyleDisplayInfo(backStyle, pa.Graphics, r, EffectiveStyle == eDotNetBarStyle.Office2007);
                    ElementStyleDisplay.Paint(displayInfo);
                    pa.Graphics.ResetClip();
                    displayInfo.Bounds = GetBackgroundRectangle();
                    // Adjust so the title shows over the inside light border line
                    displayInfo.Bounds.X--;
                    displayInfo.Bounds.Width++;
                    insideClip = ElementStyleDisplay.GetInsideClip(displayInfo);
                    displayInfo.Bounds.X++;
                    displayInfo.Bounds.Width--;
                }

                if (insideClip != null)
                    pa.Graphics.SetClip(insideClip, CombineMode.Replace);

                m_DialogLauncherRect = Rectangle.Empty;

                if (m_TitleVisible && !this.OverflowState)
                {
                    ElementStyle style = GetTitleStyle();
                    ElementStyle styleMouseOver = GetTitleMouseOverStyle();
                    if (mouseOver && style != null && styleMouseOver != null && styleMouseOver.Custom)
                    {
                        style = style.Copy();
                        style.ApplyStyle(styleMouseOver);
                    }

                    if (style != null)
                    {
                        SimpleNodeDisplayInfo info = new SimpleNodeDisplayInfo(style, pa.Graphics, m_TitleElement, this.Font, (this.RightToLeft == RightToLeft.Yes));
                        if (m_DialogLauncherVisible)
                        {
                            if (m_DialogLauncherButton == null)
                            {
                                Rectangle textRect = m_TitleElement.TextBounds;
                                textRect.Width -= m_TitleRectangle.Height;
                                if (this.RightToLeft == RightToLeft.Yes)
                                    textRect.X += m_TitleRectangle.Height;
                                info.TextBounds = textRect;
                            }
                            else
                            {
                                if (m_MouseOverDialogLauncher && m_DialogLauncherMouseOverButton != null)
                                    m_TitleElement.Image = m_DialogLauncherMouseOverButton;
                                else
                                    m_TitleElement.Image = m_DialogLauncherButton;
                            }
                        }

                        SimpleNodeDisplay.Paint(info);

                        if (m_DialogLauncherVisible && m_TitleElement.Image == null)
                            PaintDialogLauncher(pa);
                        else
                            m_DialogLauncherRect = m_TitleElement.ImageBounds;
                    }
                }

                pa.Graphics.ResetClip();

                m_FadeImageLock.AcquireReaderLock(-1);
                try
                {
                    if (m_FadeImageState != null)
                    {
                        Graphics g = pa.Graphics;
                        Rectangle r = new Rectangle(0, 0, this.Width, this.Height);

                        System.Drawing.Imaging.ColorMatrix matrix1 = new System.Drawing.Imaging.ColorMatrix();
                        matrix1[3, 3] = (float)((float)m_FadeAlpha / 255);
                        using (System.Drawing.Imaging.ImageAttributes imageAtt = new System.Drawing.Imaging.ImageAttributes())
                        {
                            imageAtt.SetColorMatrix(matrix1);

                            g.DrawImage(m_FadeImageState, r, 0, 0, r.Width, r.Height, GraphicsUnit.Pixel, imageAtt);
                        }
                        return;
                    }
                }
                finally
                {
                    m_FadeImageLock.ReleaseReaderLock();
                }
            }
            finally
            {
                if (insideClip != null) insideClip.Dispose();
                if (disposeBackStyle && backStyle != null) backStyle.Dispose();
            }
		}
コード例 #57
0
        private static System.Drawing.Bitmap MakeGrayscale3(System.Drawing.Bitmap original)
        {
            //create a blank bitmap the same size as original
            System.Drawing.Bitmap newBitmap = new System.Drawing.Bitmap(original.Width, original.Height);

            //get a graphics object from the new image
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newBitmap);

            //create the grayscale ColorMatrix
            System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(
                       new float[][]
              {
                 new float[] {.3f, .3f, .3f, 0, 0},
                 new float[] {.59f, .59f, .59f, 0, 0},
                 new float[] {.11f, .11f, .11f, 0, 0},
                 new float[] {0, 0, 0, 1, 0},
                 new float[] {0, 0, 0, 0, 1}
              });

            //create some image attributes
            System.Drawing.Imaging.ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes();

            //set the color matrix attribute
            attributes.SetColorMatrix(colorMatrix);

            //draw the original image on the new image
            //using the grayscale color matrix
            g.DrawImage(original, new System.Drawing.Rectangle(0, 0, original.Width, original.Height),
               0, 0, original.Width, original.Height, System.Drawing.GraphicsUnit.Pixel, attributes);

            //dispose the Graphics object
            g.Dispose();
            return newBitmap;
        }
コード例 #58
0
        //────────────────────────────────────────
        /// <summary>
        /// 全体図の描画。
        /// </summary>
        /// <param name="g"></param>
        /// <param name="isOnWindow"></param>
        /// <param name="memorySprite"></param>
        /// <param name="xBase">ベースX</param>
        /// <param name="yBase">ベースY</param>
        /// <param name="scale"></param>
        /// <param name="imgOpaque"></param>
        /// <param name="isImageGrid"></param>
        /// <param name="isVisible_Infodisplay"></param>
        /// <param name="infoDisplay"></param>
        public void Perform(
            Graphics g,
            bool isOnWindow,
            MemorySpriteImpl memorySprite,
            float xBase,
            float yBase,
            float scale,
            float imgOpaque,
            bool isImageGrid,
            bool isVisible_Infodisplay,
            PartnumberconfigImpl partnumberconf,
            Usercontrolview_Infodisplay infoDisplay
            )
        {
            // ビットマップ画像の不透明度を指定します。
            System.Drawing.Imaging.ImageAttributes ia;
            {
                System.Drawing.Imaging.ColorMatrix cm =
                    new System.Drawing.Imaging.ColorMatrix();
                cm.Matrix00 = 1;
                cm.Matrix11 = 1;
                cm.Matrix22 = 1;
                cm.Matrix33 = imgOpaque;//α値。0~1か?
                cm.Matrix44 = 1;

                //ImageAttributesオブジェクトの作成
                ia = new System.Drawing.Imaging.ImageAttributes();
                //ColorMatrixを設定する
                ia.SetColorMatrix(cm);
            }
            float leftSprite = 0;
            float topSprite = 0;
            if (isOnWindow)
            {
                leftSprite += memorySprite.Lefttop.X;
                topSprite += memorySprite.Lefttop.Y;
            }

            //
            // 表示画像の長方形(Image rectangle)
            RectangleF dstIrScaled = new RectangleF(
                leftSprite + xBase,
                topSprite + yBase,
                scale * (float)memorySprite.Bitmap.Width,
                scale * (float)memorySprite.Bitmap.Height
                );
            // グリッド枠の長方形(Grid frame rectangle)
            RectangleF dstGrScaled;
            {
                float col = memorySprite.CountcolumnResult;
                float row = memorySprite.CountrowResult;
                if (col < 1)
                {
                    col = 1;
                }

                if (row < 1)
                {
                    row = 1;
                }

                float cw = memorySprite.WidthcellResult;
                float ch = memorySprite.HeightcellResult;

                //グリッドのベース
                dstGrScaled = new RectangleF(
                                scale * memorySprite.GridLefttop.X + leftSprite + xBase,
                                scale * memorySprite.GridLefttop.Y + topSprite + yBase,
                                scale * col * cw,
                                scale * row * ch
                                );
            }

            // 太さ2pxの枠が収まるサイズ
            float borderWidth = 2.0f;
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;//ドット絵のまま拡縮するように。しかし、この指定だと半ピクセル左上にずれるバグ。
            g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;//半ピクセル左上にずれるバグに対応。

            //
            // 画像描画
            g.DrawImage(
                memorySprite.Bitmap,
                new Rectangle((int)dstIrScaled.X, (int)dstIrScaled.Y, (int)dstIrScaled.Width, (int)dstIrScaled.Height),
                0,
                0,
                memorySprite.Bitmap.Width,
                memorySprite.Bitmap.Height,
                GraphicsUnit.Pixel,
                ia
                );

            // 枠線
            if (isImageGrid)
            {

                //
                // 枠線:影
                //
                // オフセット 0、0 だと、上辺、左辺の緑線、黒線が保存画像から見切れます。
                // オフセット 1、1 だと、上辺、左辺の緑線が保存画像から見切れます。
                // オフセット 2、2 だと、上辺、左辺の緑線、黒線が保存画像に入ります。
                //
                // X,Yを、2ドット右下にずらします。
                dstGrScaled.Offset(2, 2);
                // X,Yの起点をずらした分だけ、縦幅、横幅を小さくします。
                dstGrScaled.Width -= 2;
                dstGrScaled.Height -= 2;
                g.DrawRectangle(Pens.Black, dstGrScaled.X, dstGrScaled.Y, dstGrScaled.Width, dstGrScaled.Height);
                //
                //
                dstGrScaled.Offset(-1, -1);// 元の位置に戻します。
                dstGrScaled.Width += 2;// 元のサイズに戻します。
                dstGrScaled.Height += 2;

                // 格子:横線
                {
                    float h2 = infoDisplay.MemorySprite.HeightcellResult * scale;

                    for (int row = 1; row < infoDisplay.MemorySprite.CountrowResult; row++)
                    {
                        g.DrawLine(infoDisplay.GridPen,//Pens.Black,
                            dstGrScaled.X + borderWidth,
                            (float)row * h2 + dstGrScaled.Y,
                            dstGrScaled.Width + dstGrScaled.X - borderWidth - 1,
                            (float)row * h2 + dstGrScaled.Y
                            );
                    }
                }

                // 格子:影:縦線
                {
                    float w2 = infoDisplay.MemorySprite.WidthcellResult * scale;

                    for (int column = 1; column < infoDisplay.MemorySprite.CountcolumnResult; column++)
                    {
                        g.DrawLine(infoDisplay.GridPen,//Pens.Black,
                            (float)column * w2 + dstGrScaled.X,
                            dstGrScaled.Y + borderWidth - 1,//上辺の枠と隙間を空けないように-1で調整。
                            (float)column * w2 + dstGrScaled.X,
                            dstGrScaled.Height + dstGrScaled.Y - borderWidth - 1
                            );
                    }
                }

                //
                // 枠線:緑
                //
                // 上辺、左辺の 0、0 と、
                // 右辺、下辺の -2、 -2 に線を引きます。
                //
                // 右辺、下辺が 0、0 だと画像外、
                // 右辺、下辺が -1、-1 だと影線の位置になります。
                dstGrScaled.Width -= 2;
                dstGrScaled.Height -= 2;
                g.DrawRectangle(Pens.Green, dstGrScaled.X, dstGrScaled.Y, dstGrScaled.Width, dstGrScaled.Height);
            }

            // 部品番号の描画
            if (partnumberconf.Visibled)
            {
                //
                // 数字は桁が多くなると横幅が伸びます。「0」「32」「105」
                // 特例で1桁は2桁扱いとして、「横幅÷桁数」が目安です。
                //

                // 最終部品番号
                int numberLast = (int)(infoDisplay.MemorySprite.CountrowResult * infoDisplay.MemorySprite.CountcolumnResult - 1) + partnumberconf.FirstIndex;
                // 最終部品番号の桁数
                int digit = numberLast.ToString().Length;
                if(1==digit)
                {
                    digit = 2;//特例で1桁は2桁扱いとします。
                }
                float fontPtScaled = scale * memorySprite.WidthcellResult / digit;

                //partnumberconf.Font = new Font("MS ゴシック", fontPt);
                partnumberconf.Font = new Font("メイリオ", fontPtScaled);

                for (int row = 0; row < infoDisplay.MemorySprite.CountrowResult; row++)
                {
                    for (int column = 0; column < infoDisplay.MemorySprite.CountcolumnResult; column++)
                    {
                        int number = (int)(row * infoDisplay.MemorySprite.CountcolumnResult + column) + partnumberconf.FirstIndex;
                        string text = number.ToString();
                        SizeF stringSizeScaled = g.MeasureString(text, partnumberconf.Font);

                        g.DrawString(text, partnumberconf.Font, partnumberconf.Brush,
                            new PointF(
                                scale * (column * memorySprite.WidthcellResult + memorySprite.WidthcellResult / 2) - stringSizeScaled.Width / 2 + dstGrScaled.X,
                                scale * (row * memorySprite.HeightcellResult + memorySprite.HeightcellResult / 2) - stringSizeScaled.Height / 2 + dstGrScaled.Y
                                ));
                    }
                }
            }

            // 情報欄の描画
            if (isVisible_Infodisplay)
            {
                int dy;
                if (isOnWindow)
                {
                    dy = 100;
                }
                else
                {
                    dy = 4;// 16;
                }
                infoDisplay.Paint(g, isOnWindow, dy, scale);
            }
        }
コード例 #59
0
        private void PaintThemed(ItemPaintArgs pa)
        {
            System.Drawing.Graphics g = pa.Graphics;
            ThemeToolbar theme = pa.ThemeToolbar;
            ThemeToolbarParts part = ThemeToolbarParts.Button;
            ThemeToolbarStates state = ThemeToolbarStates.Normal;
            eTextFormat format = pa.ButtonStringFormat; //GetStringFormat();
            Color textColor = SystemColors.ControlText;

            Rectangle rectImage = Rectangle.Empty;
            Rectangle itemRect = m_Rect;

            Font font = null;
            CompositeImage image = GetImage();

            if (m_Font != null)
                font = m_Font;
            else
                font = GetFont(pa, false);

            bool bSplitButton = (this.SubItems.Count > 0 || this.PopupType == ePopupType.Container) && this.ShowSubItems && !m_SubItemsRect.IsEmpty;

            if (bSplitButton)
                part = ThemeToolbarParts.SplitButton;

            // Calculate image position
            if (image != null)
            {
                if (m_ImagePosition == eImagePosition.Top || m_ImagePosition == eImagePosition.Bottom)
                    rectImage = new Rectangle(m_ImageDrawRect.X, m_ImageDrawRect.Y, itemRect.Width, m_ImageDrawRect.Height);
                else
                    rectImage = new Rectangle(m_ImageDrawRect.X, m_ImageDrawRect.Y, m_ImageDrawRect.Width, m_ImageDrawRect.Height);

                rectImage.Offset(itemRect.Left, itemRect.Top);
                rectImage.Offset((rectImage.Width - this.ImageSize.Width) / 2, (rectImage.Height - this.ImageSize.Height) / 2);
                rectImage.Width = this.ImageSize.Width;
                rectImage.Height = this.ImageSize.Height;
            }

            // Set the state and text brush
            if (!GetEnabled(pa.ContainerControl))
            {
                state = ThemeToolbarStates.Disabled;
                textColor = pa.Colors.ItemDisabledText;
            }
            else if (m_MouseDown)
            {
                state = ThemeToolbarStates.Pressed;
                textColor = pa.Colors.ItemPressedText;
            }
            else if (m_MouseOver && m_Checked)
            {
                state = ThemeToolbarStates.HotChecked;
                textColor = pa.Colors.ItemHotText;
            }
            else if (m_MouseOver || m_Expanded)
            {
                state = ThemeToolbarStates.Hot;
                textColor = pa.Colors.ItemHotText;
            }
            else if (m_Checked)
            {
                state = ThemeToolbarStates.Checked;
                textColor = pa.Colors.ItemCheckedText;
            }
            else
                textColor = pa.Colors.ItemText;

            Rectangle backRect = m_Rect;
            if (m_HotTrackingStyle == eHotTrackingStyle.Image && image != null)
            {
                backRect = rectImage;
                backRect.Inflate(3, 3);
            }
            else if (bSplitButton)
            {
                backRect.Width = backRect.Width - m_SubItemsRect.Width;
            }

            // Draw Button Background
            if (m_HotTrackingStyle != eHotTrackingStyle.None)
            {
                theme.DrawBackground(g, part, state, backRect);
            }

            // Draw Image
            if (image != null && m_ButtonStyle != eButtonStyle.TextOnlyAlways)
            {
                if (state == ThemeToolbarStates.Normal && m_HotTrackingStyle == eHotTrackingStyle.Color)
                {
                    // Draw gray-scale image for this hover style...
                    float[][] array = new float[5][];
                    array[0] = new float[5] { 0.2125f, 0.2125f, 0.2125f, 0, 0 };
                    array[1] = new float[5] { 0.5f, 0.5f, 0.5f, 0, 0 };
                    array[2] = new float[5] { 0.0361f, 0.0361f, 0.0361f, 0, 0 };
                    array[3] = new float[5] { 0, 0, 0, 1, 0 };
                    array[4] = new float[5] { 0.2f, 0.2f, 0.2f, 0, 1 };
                    System.Drawing.Imaging.ColorMatrix grayMatrix = new System.Drawing.Imaging.ColorMatrix(array);
                    System.Drawing.Imaging.ImageAttributes att = new System.Drawing.Imaging.ImageAttributes();
                    att.SetColorMatrix(grayMatrix);
                    //g.DrawImage(image,rectImage,0,0,image.Width,image.Height,GraphicsUnit.Pixel,att);
                    image.DrawImage(g, rectImage, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, att);
                }
                else if (state == ThemeToolbarStates.Normal && !image.IsIcon)
                {
                    // Draw image little bit lighter, I decied to use gamma it is easy
                    System.Drawing.Imaging.ImageAttributes lightImageAttr = new System.Drawing.Imaging.ImageAttributes();
                    lightImageAttr.SetGamma(.7f, System.Drawing.Imaging.ColorAdjustType.Bitmap);
                    //g.DrawImage(image,rectImage,0,0,image.Width,image.Height,GraphicsUnit.Pixel,lightImageAttr);
                    image.DrawImage(g, rectImage, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, lightImageAttr);
                }
                else
                {
                    image.DrawImage(g, rectImage);
                }
            }

            // Draw Text
            if (m_ButtonStyle == eButtonStyle.ImageAndText || m_ButtonStyle == eButtonStyle.TextOnlyAlways || image == null /*|| !this.IsOnBar*/) // Commented out becouse it caused text to be drawn if item is not on bar no matter what
            {
                Rectangle rectText = m_TextDrawRect;
                if (m_ImagePosition == eImagePosition.Top || m_ImagePosition == eImagePosition.Bottom)
                {
                    if (m_Orientation == eOrientation.Vertical)
                    {
                        rectText = new Rectangle(m_TextDrawRect.X, m_TextDrawRect.Y, m_TextDrawRect.Width, m_TextDrawRect.Height);
                    }
                    else
                    {
                        rectText = new Rectangle(m_TextDrawRect.X, m_TextDrawRect.Y, itemRect.Width, m_TextDrawRect.Height);
                        if ((this.SubItems.Count > 0 || this.PopupType == ePopupType.Container) && this.ShowSubItems)
                            rectText.Width -= 10;
                    }
                    format |= eTextFormat.HorizontalCenter;
                }

                rectText.Offset(itemRect.Left, itemRect.Top);

                if (m_Orientation == eOrientation.Vertical)
                {
                    g.RotateTransform(90);
                    TextDrawing.DrawStringLegacy(g, m_Text, font, textColor, new Rectangle(rectText.Top, -rectText.Right, rectText.Height, rectText.Width), format);
                    g.ResetTransform();
                }
                else
                {
                    if (rectText.Right > m_Rect.Right)
                        rectText.Width = m_Rect.Right - rectText.Left;
                    TextDrawing.DrawString(g, m_Text, font, textColor, rectText, format);
                    if (!this.DesignMode && this.Focused && !pa.IsOnMenu && !pa.IsOnMenuBar)
                    {
                        //SizeF szf=g.MeasureString(m_Text,font,rectText.Width,format);
                        Rectangle r = rectText;
                        //r.Width=(int)Math.Ceiling(szf.Width);
                        //r.Height=(int)Math.Ceiling(szf.Height);
                        //r.Inflate(1,1);
                        System.Windows.Forms.ControlPaint.DrawFocusRectangle(g, r);
                    }
                }
            }

            // If it has subitems draw the triangle to indicate that
            if (bSplitButton)
            {
                part = ThemeToolbarParts.SplitButtonDropDown;

                if (!GetEnabled(pa.ContainerControl))
                    state = ThemeToolbarStates.Disabled;
                else
                    state = ThemeToolbarStates.Normal;

                if (m_HotTrackingStyle != eHotTrackingStyle.None && m_HotTrackingStyle != eHotTrackingStyle.Image && GetEnabled(pa.ContainerControl))
                {
                    if (m_Expanded || m_MouseDown)
                        state = ThemeToolbarStates.Pressed;
                    else if (m_MouseOver && m_Checked)
                        state = ThemeToolbarStates.HotChecked;
                    else if (m_Checked)
                        state = ThemeToolbarStates.Checked;
                    else if (m_MouseOver)
                        state = ThemeToolbarStates.Hot;
                }

                if (m_Orientation == eOrientation.Horizontal)
                {
                    Rectangle r = m_SubItemsRect;
                    r.Offset(itemRect.X, itemRect.Y);
                    theme.DrawBackground(g, part, state, r);
                }
                else
                {
                    Rectangle r = m_SubItemsRect;
                    r.Offset(itemRect.X, itemRect.Y);
                    theme.DrawBackground(g, part, state, r);
                }
                //g.DrawLine(new Pen(pa.Colors.ItemHotBorder)/*SystemPens.Highlight*/,itemRect.Left,itemRect.Top+m_SubItemsRect.Top,itemRect.Right-2,itemRect.Top+m_SubItemsRect.Top);
            }

            if (this.Focused && this.DesignMode)
            {
                Rectangle r = itemRect;
                r.Inflate(-1, -1);
                DesignTime.DrawDesignTimeSelection(g, r, pa.Colors.ItemDesignTimeBorder);
            }

            if (image != null)
                image.Dispose();
        }
コード例 #60
0
        internal static void PaintSystemButton(System.Drawing.Graphics g, SystemButton btn, Rectangle r, bool MouseDown, bool MouseOver, bool Disabled)
        {
            // Draw state if any
            if (MouseDown)
            {
                g.FillRectangle(new SolidBrush(ColorFunctions.PressedBackColor(g)), r);
                NativeFunctions.DrawRectangle(g, SystemPens.Highlight, r);
            }
            else if (MouseOver)
            {
                g.FillRectangle(new SolidBrush(ColorFunctions.HoverBackColor(g)), r);
                NativeFunctions.DrawRectangle(g, SystemPens.Highlight, r);
            }

            Bitmap bmp = new Bitmap(r.Width, r.Height, g);
            Graphics gBmp = Graphics.FromImage(bmp);
            Rectangle rBtn = new Rectangle(0, 0, r.Width, r.Height);
            rBtn.Inflate(0, -1);
            Rectangle rClip = rBtn;
            rClip.Inflate(-1, -1);
            using (SolidBrush brush = new SolidBrush(SystemColors.Control))
                gBmp.FillRectangle(brush, 0, 0, r.Width, r.Height);
            gBmp.SetClip(rClip);
            System.Windows.Forms.ControlPaint.DrawCaptionButton(gBmp, rBtn, (System.Windows.Forms.CaptionButton)btn, System.Windows.Forms.ButtonState.Flat);
            gBmp.ResetClip();
            gBmp.Dispose();

            bmp.MakeTransparent(SystemColors.Control);
            if (Disabled)
            {
                float[][] array = new float[5][];
                array[0] = new float[5] { 0, 0, 0, 0, 0 };
                array[1] = new float[5] { 0, 0, 0, 0, 0 };
                array[2] = new float[5] { 0, 0, 0, 0, 0 };
                array[3] = new float[5] { .5f, .5f, .5f, .5f, 0 };
                array[4] = new float[5] { 0, 0, 0, 0, 0 };
                System.Drawing.Imaging.ColorMatrix grayMatrix = new System.Drawing.Imaging.ColorMatrix(array);
                System.Drawing.Imaging.ImageAttributes disabledImageAttr = new System.Drawing.Imaging.ImageAttributes();
                disabledImageAttr.ClearColorKey();
                disabledImageAttr.SetColorMatrix(grayMatrix);
                g.DrawImage(bmp, r, 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, disabledImageAttr);
            }
            else
            {
                if (MouseDown)
                    r.Offset(1, 1);
                g.DrawImageUnscaled(bmp, r);
            }

        }