protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Graphics G = e.Graphics;
            //利用位图作为纹理创建纹理画刷
            TextureBrush textureBrush1 = new TextureBrush(Properties.Resources.test);
            G.FillRectangle(textureBrush1, 40, 0, 40, 120);
            G.FillRectangle(textureBrush1, 0, 40, 120, 40);
            //利用位置的指定区域作为纹理创建纹理画刷
            TextureBrush textureBrush2 = new TextureBrush(Properties.Resources.test, new Rectangle(10, 10, 28, 28));
            G.FillRectangle(textureBrush2, 180, 0, 40, 120);
            G.FillRectangle(textureBrush2, 140, 40, 120, 40);
            TextureBrush textureBrush3 = new TextureBrush(Properties.Resources.test, new Rectangle(10, 10, 28, 28));
            textureBrush3.WrapMode = WrapMode.TileFlipXY;           //设置纹理图像的渐变方式
            G.FillRectangle(textureBrush3, 30, 140, 60, 120);
            G.FillRectangle(textureBrush3, 0, 170, 120, 60);
            float[][] newColorMatrix = new float[][]{               //颜色变换矩形
            new float[]{0.2f,0,0,0,0},                          //红色分量
            new float[]{0,0.6f,0,0,0},                          //绿色分量
            new float[]{0,0,0.2f,0,0},                          //蓝色分量
            new float[]{0,0,0,0.5f,0},                          //透明度分量
            new float[]{0,0,0,0,1}};                            //始终为1
            ColorMatrix colorMatrix = new ColorMatrix(newColorMatrix);
            ImageAttributes imageAttributes = new ImageAttributes();
            imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
            TextureBrush textureBrush4 = new TextureBrush(Properties.Resources.test, new Rectangle(0, 0, 48, 48), imageAttributes);
            textureBrush4.WrapMode = WrapMode.TileFlipXY;
            G.FillRectangle(textureBrush4, 170, 140, 60, 120);
            G.FillRectangle(textureBrush4, 140, 170, 120, 60);
            textureBrush1.Dispose();                                //释放画刷
            textureBrush2.Dispose();                                //释放画刷
            textureBrush3.Dispose();                                //释放画刷
            textureBrush4.Dispose();                                //释放画刷
        }
예제 #2
0
 private static void RoundImageTransparent(Image bitmap, int roundedDia)
 {
     Brush brush = new TextureBrush(bitmap);
     Graphics g = Graphics.FromImage(bitmap);
     g.Clear(Color.Transparent);
     Genetibase.UI.Drawing.Grpahics.FillRoundedRectangle(g, brush, new Rectangle(0, 0, bitmap.Width, bitmap.Height), 30);
     g.Dispose();
     brush.Dispose();
     Rounded = true;
 }
예제 #3
0
        public static Bitmap RoundImage( Image bitmap )
        {
            Bitmap retImage = new Bitmap(bitmap.Width, bitmap.Height);
            Graphics g = Graphics.FromImage(retImage);
            g.Clear(Color.Transparent);
            Brush brush = new TextureBrush(bitmap);
            FillRoundedRectangle(g, new Rectangle(0, 0, bitmap.Width, bitmap.Height), roundedDia, brush);

            g.Dispose();
            brush.Dispose();

            return retImage;
        }
예제 #4
0
        public override System.Drawing.Bitmap GetImage()
        {
            Bitmap bmp = new Bitmap(Width, Height);
            Graphics g = Graphics.FromImage(bmp);

            using( TextureBrush brush = new TextureBrush(Ultima.Gumps.GetGump(Index)) )
            {
                g.FillRectangle(brush, new Rectangle(0, 0, Width, Height));
                brush.Dispose();
            }

            g.Dispose();
            return bmp;
        }
예제 #5
0
        public static Bitmap dropShadow(Bitmap original)
        {
            Bitmap dest = new Bitmap(original.Width + shadowSize, original.Height + shadowSize);
            Graphics g = Graphics.FromImage(dest);

            TextureBrush shadowRightBrush = new TextureBrush(shadowRight, WrapMode.Tile);
            TextureBrush shadowDownBrush = new TextureBrush(shadowDown, WrapMode.Tile);

            shadowRightBrush.TranslateTransform(original.Width - shadowSize, 0);
            shadowDownBrush.TranslateTransform(0, original.Height - shadowSize);

            Rectangle shadowDownRectangle = new Rectangle(
                shadowSize,                               // X
                original.Height, //- shadowSize,                            // Y
                original.Width - shadowSize,// - (shadowSize * 2 + shadowMargin),        // width (stretches)
                shadowSize                                               // height
                );

            Rectangle shadowRightRectangle = new Rectangle(
                original.Width,// - shadowSize,                             // X
                shadowSize, // + shadowMargin,                      // Y
                shadowSize,                                     // width
                original.Height -shadowSize // - (shadowSize * 2 + shadowMargin)        // height (stretches)
                );

            // And draw the shadow on the right and at the bottom.

            g.FillRectangle(shadowDownBrush, shadowDownRectangle);
            g.FillRectangle(shadowRightBrush, shadowRightRectangle);

            // 隅っこ三つ
            g.DrawImage(shadowTopRight, new Rectangle(original.Width, 0, shadowSize, shadowSize));
            g.DrawImage(shadowDownRight, new Rectangle(original.Width, original.Height, shadowSize, shadowSize));
            g.DrawImage(shadowDownLeft, new Rectangle(0, original.Height, shadowSize, shadowSize));

            g.DrawImage(original, new Rectangle(new Point(0, 0), new Size(original.Width, original.Height)));

            shadowDownBrush.Dispose();
            shadowRightBrush.Dispose();

            shadowDownBrush = null;
            shadowRightBrush = null;

            return dest;
        }
예제 #6
0
        protected override void OnPaint(PaintEventArgs e)
        {
            {

                // get the graphics obj used to paint the panel
                Graphics graphic = e.Graphics;
                // create a brush with playerColor colored paint
                System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(playerColor);
                // the image is bound to 150*150 size starting from 60,60 top left origin
                System.Drawing.TextureBrush myBrush2 = new System.Drawing.TextureBrush(pieceTexture, new Rectangle(60, 60, 150, 150)); // the bounding rectangle of the texture image

                myBrush2.WrapMode = System.Drawing.Drawing2D.WrapMode.Clamp;
                // scale down the texture from 256,256
                myBrush2.Transform = new System.Drawing.Drawing2D.Matrix(35.0f / 256.0f, 0.0f, 0.0f, 35.0f / 256.0f, 0.0f, 0.0f);
                // draw a filled elipse with the brush
                // TODO: change this to an image
                graphic.FillEllipse(myBrush2, new Rectangle(0, 0, this.Height - 1, this.Width - 1)); // the bounding rectangle of the piecePanel

                // cleanup the tools
                myBrush.Dispose();
                myBrush2.Dispose();
                graphic.Dispose();
            }
        }
예제 #7
0
		/// <summary>
		/// 繪畫方法
		/// </summary>
		/// <param name="e">事件參數</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            //System.Diagnostics.Debug.WriteLine("Paint " + this.Name + "  Pos: "+this.Position.ToString());
            if (!this.IsDisposed)
            {
                int mSteepTotal = mSteepWidth + mSteepDistance;
                float mUtilWidth = this.Width - 6 + mSteepDistance;

                if (mDobleBack == null)
                {
                    mUtilWidth = this.Width - 6 + mSteepDistance;
                    int mMaxSteeps = (int)(mUtilWidth / mSteepTotal);
                    this.Width = 6 + mSteepTotal * mMaxSteeps;

                    mDobleBack = new Bitmap(this.Width, this.Height);

                    Graphics g2 = Graphics.FromImage(mDobleBack);

                    CreatePaintElements();

                    g2.Clear(mColorBackGround);

                    if (this.BackgroundImage != null)
                    {
                        TextureBrush textuBrush = new TextureBrush(this.BackgroundImage, WrapMode.Tile);
                        g2.FillRectangle(textuBrush, 0, 0, this.Width, this.Height);
                        textuBrush.Dispose();
                    }
                    //				g2.DrawImage()

                    g2.DrawRectangle(mPenOut2, outnnerRect2);
                    g2.DrawRectangle(mPenOut, outnnerRect);
                    g2.DrawRectangle(mPenIn, innerRect);
                    g2.Dispose();

                }

                Image ima = new Bitmap(mDobleBack);

                Graphics gtemp = Graphics.FromImage(ima);

                int mCantSteeps = (int)((((float)mValue - mMin) / (mMax - mMin)) * mUtilWidth / mSteepTotal);

                for (int i = 0; i < mCantSteeps; i++)
                {
                    DrawSteep(gtemp, i);
                }

                if (this.Text != String.Empty)
                {
                    gtemp.TextRenderingHint = TextRenderingHint.AntiAlias;
                    DrawCenterString(gtemp, this.ClientRectangle);
                }

                e.Graphics.DrawImage(ima, e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle, GraphicsUnit.Pixel);
                ima.Dispose();
                gtemp.Dispose();

            }

        }
예제 #8
0
        // Create dirty text effect
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

            Bitmap canvas = Canvas.GenImage(ClientSize.Width, ClientSize.Height);
            // Load the dirty image from file
            Bitmap canvasDirty = new Bitmap("..\\..\\..\\CommonImages\\dirty-texture.png");

            // Text context to store string and font info to be sent as parameter to Canvas methods
            TextContext context = new TextContext();

            FontFamily fontFamily = new FontFamily("Arial Black");
            context.fontFamily = fontFamily;
            context.fontStyle = FontStyle.Regular;
            context.nfontSize = 48;

            context.pszText = "DIRTY";
            context.ptDraw = new Point(5, 70);

            // Load the texture image from file
            Bitmap texture = new Bitmap("..\\..\\..\\CommonImages\\texture_blue.jpg");

            Bitmap texture2 = Canvas.GenImage(ClientSize.Width, ClientSize.Height);
            // Draw the texture against the red dirty mask onto the 2nd texture
            Canvas.ApplyImageToMask(texture, canvasDirty, texture2, MaskColor.Red, false);
            TextureBrush textureBrush = new TextureBrush(texture2);

            Bitmap textureShadow = Canvas.GenImage(ClientSize.Width, ClientSize.Height);
            // Draw the gray color against the red dirty mask onto the shadow texture
            Canvas.ApplyColorToMask(Color.FromArgb(0xaa, 0xcc, 0xcc, 0xcc), canvasDirty, textureShadow, MaskColor.Red);
            // Create texture brush for the shadow
            TextureBrush shadowBrush = new TextureBrush(textureShadow);

            // Create strategy for the shadow with the shadow brush
            var strategyShadow = Canvas.TextNoOutline(shadowBrush);

            Bitmap canvasTemp = Canvas.GenImage(ClientSize.Width, ClientSize.Height);
            // Draw the shadow image first onto the temp canvas
            Canvas.DrawTextImage(strategyShadow, canvasTemp, new Point(0, 0), context);

            // Create strategy for the text body
            var strategy = Canvas.TextNoOutline(textureBrush);
            // Draw text body
            Canvas.DrawTextImage(strategy, canvas, new Point(0,0), context);

            // Draw the shadow image (canvasTemp) shifted -3, -3
            e.Graphics.DrawImage(canvasTemp, 3, 3, ClientSize.Width - 3, ClientSize.Height - 3);
            // Then draw the rendered image onto window
            e.Graphics.DrawImage(canvas, 0, 0, ClientSize.Width, ClientSize.Height);

            e.Graphics.Dispose();
            texture.Dispose();
            texture2.Dispose();
            textureShadow.Dispose();

            canvasDirty.Dispose();

            canvas.Dispose();
            canvasTemp.Dispose();

            strategyShadow.Dispose();
            strategy.Dispose();

            textureBrush.Dispose();
            shadowBrush.Dispose();
        }
예제 #9
0
		/// <summary>
		/// Paints style background image.
		/// </summary>
		/// <param name="e">Style display information.</param>
		public static void PaintBackgroundImage(ElementStyleDisplayInfo e)
		{
            ElementStyle style = GetElementStyle(e.Style);
			if(style.BackgroundImage==null)
				return;

            Rectangle bounds = DisplayHelp.GetDrawRectangle(ElementStyleDisplay.GetBackgroundRectangle(style, e.Bounds));
			GraphicsPath path;
			if (e.Graphics.SmoothingMode == SmoothingMode.AntiAlias)
			{
				Rectangle r = e.Bounds;
				r.Width--;
				//r.Height--;
                path = ElementStyleDisplay.GetBackgroundPath(style, r);
			}
			else
                path = ElementStyleDisplay.GetBackgroundPath(style, e.Bounds);
			
			ImageAttributes imageAtt=null;

            if (style.BackgroundImageAlpha != 255)
			{
				ColorMatrix colorMatrix=new ColorMatrix();
                colorMatrix.Matrix33 = 255 - style.BackgroundImageAlpha;
				imageAtt=new ImageAttributes();
				imageAtt.SetColorMatrix(colorMatrix,ColorMatrixFlag.Default,ColorAdjustType.Bitmap);
			}

			Region clip=e.Graphics.Clip;
			e.Graphics.SetClip(path);

            eStyleBackgroundImage imagePosition = style.BackgroundImagePosition;
            bool transform = false;
            Image backgroundImage = style.BackgroundImage;

            if (e.RightToLeft)
            {
                if (imagePosition == eStyleBackgroundImage.TopLeft)
                {
                    imagePosition = eStyleBackgroundImage.TopRight;
                    transform = true;
                }
                else if (imagePosition == eStyleBackgroundImage.TopRight)
                    imagePosition = eStyleBackgroundImage.TopLeft;
                else if (imagePosition == eStyleBackgroundImage.BottomLeft)
                    imagePosition = eStyleBackgroundImage.BottomRight;
                else if (imagePosition == eStyleBackgroundImage.BottomRight)
                    imagePosition = eStyleBackgroundImage.BottomLeft;
            }

            if (transform)
            {
                backgroundImage = backgroundImage.Clone() as Image;
                backgroundImage.RotateFlip(RotateFlipType.RotateNoneFlipX);
            }

            switch (imagePosition)
			{
				case eStyleBackgroundImage.Stretch:
				{
					if(imageAtt!=null)
                        e.Graphics.DrawImage(backgroundImage, bounds, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel, imageAtt);
					else
                        e.Graphics.DrawImage(backgroundImage, bounds, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel);
					break;
				}
				case eStyleBackgroundImage.Center:
				{
                    Rectangle destRect = new Rectangle(bounds.X, bounds.Y, backgroundImage.Width, backgroundImage.Height);
                    if (bounds.Width > backgroundImage.Width)
                        destRect.X += (bounds.Width - backgroundImage.Width) / 2;
                    if (bounds.Height > backgroundImage.Height)
                        destRect.Y += (bounds.Height - backgroundImage.Height) / 2;
					if(imageAtt!=null)
                        e.Graphics.DrawImage(backgroundImage, destRect, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel, imageAtt);
					else
                        e.Graphics.DrawImage(backgroundImage, destRect, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel);
					
					break;
				}
				case eStyleBackgroundImage.TopLeft:
				case eStyleBackgroundImage.TopRight:
				case eStyleBackgroundImage.BottomLeft:
				case eStyleBackgroundImage.BottomRight:
				{
                    Rectangle destRect = new Rectangle(bounds.X, bounds.Y, backgroundImage.Width, backgroundImage.Height);
                    if (imagePosition == eStyleBackgroundImage.TopRight)
                        destRect.X = bounds.Right - backgroundImage.Width;
                    else if (imagePosition == eStyleBackgroundImage.BottomLeft)
                        destRect.Y = bounds.Bottom - backgroundImage.Height;
                    else if (imagePosition == eStyleBackgroundImage.BottomRight)
					{
                        destRect.Y = bounds.Bottom - backgroundImage.Height;
                        destRect.X = bounds.Right - backgroundImage.Width;
					}

					if(imageAtt!=null)
                        e.Graphics.DrawImage(backgroundImage, destRect, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel, imageAtt);
					else
                        e.Graphics.DrawImage(backgroundImage, destRect, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel);
					break;
				}
				case eStyleBackgroundImage.Tile:
				{
					if(imageAtt!=null)
					{
                        if (bounds.Width > backgroundImage.Width || bounds.Height > backgroundImage.Height)
						{
							int x=bounds.X,y=bounds.Y;
							while(y<bounds.Bottom)
							{
								while(x<bounds.Right)
								{
                                    Rectangle destRect = new Rectangle(x, y, backgroundImage.Width, backgroundImage.Height);
									if(destRect.Right>bounds.Right)
										destRect.Width=destRect.Width-(destRect.Right-bounds.Right);
									if(destRect.Bottom>bounds.Bottom)
										destRect.Height=destRect.Height-(destRect.Bottom-bounds.Bottom);
                                    e.Graphics.DrawImage(backgroundImage, destRect, 0, 0, destRect.Width, destRect.Height, GraphicsUnit.Pixel, imageAtt);
                                    x += backgroundImage.Width;
								}
								x=bounds.X;
                                y += backgroundImage.Height;
							}
						}
						else
						{
                            e.Graphics.DrawImage(backgroundImage, new Rectangle(0, 0, backgroundImage.Width, backgroundImage.Height), 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel, imageAtt);
						}
					}
					else
					{
                        TextureBrush brush = new TextureBrush(backgroundImage);
						brush.WrapMode=WrapMode.Tile;
						e.Graphics.FillPath(brush,path);
						brush.Dispose();
					}
					break;
				}
			}
            if (transform)
            {
                backgroundImage.Dispose();
            }

			if (clip != null)
				e.Graphics.Clip = clip;
			else
				e.Graphics.ResetClip();
		}
예제 #10
0
		public void Dispose_Image ()
		{
			TextureBrush t = new TextureBrush (image);
			t.Dispose ();
			Assert.IsNotNull (t.Image, "Image");
		}
예제 #11
0
        public static void Wash(Bitmap b,Color washColor)
        {
            Rectangle rect = new Rectangle( 0,0,b.Width,b.Height);
            Brush backgroundBrush = new TextureBrush(b);
            Graphics g = Graphics.FromImage(b);
            Brush newBrush = new SolidBrush(Color.FromArgb(128, washColor));

            if (!Rounded)
            {
                g.FillRectangle(backgroundBrush, rect);
                g.FillRectangle(newBrush, rect);
            }
            else
            {
                Genetibase.UI.NuGenImageWorks.Grpahics.FillRoundedRectangle(g, backgroundBrush, rect, 30);
                Genetibase.UI.NuGenImageWorks.Grpahics.FillRoundedRectangle(g, newBrush, rect, 30);                
            }

            newBrush.Dispose();
            newBrush = null;

            g.Dispose();
            backgroundBrush.Dispose();

            g = null;
            backgroundBrush = null;
        }
예제 #12
0
        private bool ProcessPrintRequest(int pageNumberStart, int pageNumberEnd, bool showData)
        {
            bool isLandscape = false;
            bool exitPrint = false;

            try
            {
                List<Page> allPages = view.GetMetadata().GetViewPages(view);
                List<Page> pages = new List<Page>();
                pages = allPages.GetRange(pageNumberStart - 1, 1 + pageNumberEnd - pageNumberStart);

                foreach (Page page in pages)
                {
                    printDocument = new System.Drawing.Printing.PrintDocument();
                    printDocument.PrintPage += new PrintPageEventHandler(printDocument_PrintPage);
                    DataRow row = page.GetMetadata().GetPageSetupData(view);
                    isLandscape = row["Orientation"].ToString().ToLower() == "landscape";
                    Panel printPanel = new Panel();

                    float dpiX;
                    Graphics graphics = printPanel.CreateGraphics();
                    dpiX = graphics.DpiX;

                    int height = (int)row["Height"];
                    int width = (int)row["Width"];

                    if (dpiX != 96)
                    {
                        float scaleFactor = (dpiX * 1.041666666f) / 100;
                        height = Convert.ToInt32(((float)height) * (float)scaleFactor);
                        width = Convert.ToInt32(((float)width) * (float)scaleFactor);
                    }

                    if (isLandscape)
                    {
                        printPanel.Size = new System.Drawing.Size(height, width);
                        printDocument.DefaultPageSettings.Landscape = true;
                    }
                    else
                    {
                        printPanel.Size = new System.Drawing.Size(width, height);
                    }

                    ControlFactory factory = ControlFactory.Instance;
                    List<Control> pageControls = factory.GetPageControls(page, printPanel.Size);

                    SortedList<FieldGroupBox, System.Drawing.Point> groupsOnPage = new SortedList<FieldGroupBox, System.Drawing.Point>(new GroupZeeOrderComparer());
                    List<Control> childrenOnPage = new List<Control>();
                    List<Control> orphansOnPage = new List<Control>();
                    ArrayList namesOfChildenOnPage = new ArrayList();

                    Panel panel = _fieldPanel;

                    foreach (Control control in pageControls)
                    {
                        Control printControl = control;
                        Field field = factory.GetAssociatedField(control);
                        field = this.view.Fields[field.Name];

                        if (control is DragableGroupBox == false)
                        {
                            try
                            {
                                if (control is RichTextBox)
                                {
                                    printControl = new TextBox();

                                    ((TextBoxBase)printControl).BorderStyle = ((TextBoxBase)control).BorderStyle;
                                    ((TextBoxBase)printControl).Multiline = true;

                                    printControl.Left = control.Left;
                                    printControl.Top = control.Top;
                                    printControl.Height = control.Height;
                                    printControl.Width = control.Width;
                                    printControl.Font = control.Font;
                                }

                                printPanel.Controls.Add(printControl);
                            }
                            catch
                            {
                                return false;
                            }
                        }

                        if (printControl is Label) continue;
                        if (printControl is FieldGroupBox) continue;

                        if (showData)
                        {
                            if (field is ImageField)
                            {
                                this.canvas.GetFieldDataIntoControl(field as ImageField, printControl as PictureBox);
                            }
                            else if (field is YesNoField)
                            {
                                this.canvas.GetFieldDataIntoControl(field as YesNoField, printControl as ComboBox);
                                if (((ComboBox)printControl).SelectedValue == null)
                                {
                                    foreach (Control panelControl in panel.Controls)
                                    {
                                        if (panelControl is Label) continue;
                                        if (panelControl is FieldGroupBox) continue;

                                        Field panelfield = factory.GetAssociatedField(panelControl);
                                        panelfield = this.view.Fields[field.Name];

                                        if (panelfield.Name == field.Name)
                                        {
                                            string holdit = ((YesNoField)panelfield).CurrentRecordValueString.ToString();
                                            string yes = "1";
                                            string no = "0";

                                            if (holdit.Contains(yes))
                                            {
                                                printControl.Text = "Yes";
                                            }
                                            else if (holdit.Contains(no))
                                            {
                                                printControl.Text = "No";
                                            }
                                        }
                                    }
                                }
                            }
                            else if (printControl is TextBox || printControl is ComboBox || printControl is CheckBox || printControl is MaskedTextBox || printControl is DataGridView || printControl is GroupBox || printControl is DateTimePicker)
                            {
                                if (field is MirrorField)
                                {
                                    this.canvas.GetMirrorData(field as MirrorField, printControl);
                                }
                                else if (field is IDataField || printControl is DataGridView)
                                {
                                    if (printControl is TextBox)
                                    {
                                        this.canvas.GetTextData(field, printControl);
                                    }
                                    else if (printControl is RichTextBox)
                                    {
                                        this.canvas.GetTextData(field, printControl);
                                    }
                                    else if (field is DateField)
                                    {
                                        this.canvas.GetDateData(field as DateField, printControl);
                                    }
                                    else if (field is TimeField)
                                    {
                                        this.canvas.GetTimeData(field as TimeField, printControl);
                                    }
                                    else if (field is DateTimeField)
                                    {
                                        this.canvas.GetDateTimeData(field as DateTimeField, printControl);
                                    }
                                    else if (printControl is MaskedTextBox)
                                    {
                                        if (((IDataField)field).CurrentRecordValueObject != null)
                                        {
                                            if (((MaskedTextBox)printControl).Mask != null)
                                            {
                                                if (field is NumberField && !Util.IsEmpty(((IDataField)field).CurrentRecordValueString))
                                                {
                                                    printControl.Text = FormatNumberInput(((NumberField)field).CurrentRecordValueString, ((NumberField)field).Pattern);
                                                }
                                                else
                                                {
                                                    printControl.Text = ((IDataField)field).CurrentRecordValueString;
                                                }
                                            }
                                            else
                                            {
                                                printControl.Text = ((IDataField)field).CurrentRecordValueString;
                                            }
                                        }
                                        else
                                        {
                                            printControl.Text = string.Empty;
                                        }
                                    }
                                    else if (printControl is ComboBox)
                                    {
                                        this.canvas.GetComboboxData(field, printControl);
                                    }
                                    else if (printControl is CheckBox)
                                    {
                                        this.canvas.GetCheckBoxData(field, printControl);
                                    }
                                    else if (printControl is DataGridView)
                                    {
                                        this.canvas.GetDataGridViewData(field, printControl);
                                    }
                                    else if (field is OptionField)
                                    {
                                        this.canvas.GetOptionData((OptionField)field, printControl);
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (printControl is TextBox || printControl is ComboBox)
                            {
                                if (field is IDataField || printControl is DataGridView)
                                {
                                    if (printControl is ComboBox)
                                    {
                                        ((ComboBox)printControl).Text = "";
                                    }
                                }

                                if (printControl is TextBox)
                                {
                                    ((TextBox)printControl).Text = "";
                                    ((TextBox)printControl).Enabled = true;
                                }
                            }
                        }
                    }

                    if (exitPrint)
                    {
                        break;
                    }

                    int colorValue;
                    DataTable backgroundTable = page.GetMetadata().GetPageBackgroundData(page);
                    DataRow[] rows = backgroundTable.Select("BackgroundId=" + page.BackgroundId);
                    string imageLayout = string.Empty;
                    if (rows.Length > 0)
                    {
                        imageLayout = Convert.ToString(rows[0]["ImageLayout"]);
                    }
                    Color color;
                    Image image;
                    Bitmap bufferBitmap = null;

                    if (page != null)
                    {
                        if (rows.Length > 0)
                        {
                            colorValue = Convert.ToInt32(rows[0]["Color"]);

                            if (rows[0]["Image"] != System.DBNull.Value)
                            {
                                try
                                {
                                    byte[] imageBytes = ((byte[])rows[0]["Image"]);

                                    using (MemoryStream memStream = new MemoryStream(imageBytes.Length))
                                    {
                                        memStream.Seek(0, SeekOrigin.Begin);
                                        memStream.Write(imageBytes, 0, imageBytes.Length);
                                        memStream.Seek(0, SeekOrigin.Begin);

                                        image = Image.FromStream(((Stream)memStream));
                                    }
                                }
                                catch
                                {
                                    image = null;
                                }
                            }
                            else
                            {
                                image = null;
                            }

                            if (colorValue == 0)
                            {
                                color = SystemColors.Window;
                            }
                            else
                            {
                                color = Color.FromArgb(colorValue);
                            }
                        }
                        else
                        {
                            image = null;
                            imageLayout = "None";
                            color = SystemColors.Window;
                        }
                    }
                    else
                    {
                        image = null;
                        imageLayout = "None";
                        color = SystemColors.Window;
                    }

                    if ((image == null) && (color.Equals(Color.Empty)))
                    {
                        printPanel.BackColor = Color.White;
                    }
                    else
                    {
                      /* if (showtab)
                        {
                            foreach (Control control in pageControls)
                            {
                                Field field = factory.GetAssociatedField(control);
                                if (control.TabStop == true)
                                {
                                    bool isInputField = ((Control)control) is PairedLabel == false && field.FieldType != MetaFieldType.Group;
                                    bool isLabelField = field.FieldType == MetaFieldType.LabelTitle;
                                    if (isInputField || isLabelField)
                                    {
                                        Label lbTabSquare = new Label();
                                        lbTabSquare.BackColor = control.TabStop ? Color.Black : Color.Firebrick;
                                        lbTabSquare.Padding = new Padding(2);
                                        lbTabSquare.ForeColor = Color.White;
                                        lbTabSquare.BorderStyle = BorderStyle.None;
                                        lbTabSquare.Font = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold);
                                        lbTabSquare.Text = control.TabIndex.ToString() + "  " + field.Name;
                                        lbTabSquare.Location = new Point(control.Location.X, control.Location.Y);
                                        lbTabSquare.Size = TextRenderer.MeasureText(lbTabSquare.Text, lbTabSquare.Font);
                                        lbTabSquare.Size = new Size(lbTabSquare.Size.Width + lbTabSquare.Padding.Size.Width, lbTabSquare.Size.Height + lbTabSquare.Padding.Size.Height);
                                        lbTabSquare.Tag = "showtab";
                                        lbTabSquare.BringToFront();
                                        printPanel.Controls.Add(lbTabSquare);
                                    }
                                }
                            }
                        }*/
                        printPanel.BackgroundImageLayout = ImageLayout.None;
                        if (printPanel.Size.Width > 0 && printPanel.Size.Height > 0)
                        {
                            try
                            {
                                Bitmap b = new Bitmap(printPanel.Size.Width, printPanel.Size.Height);
                                Graphics bufferGraphics = Graphics.FromImage(b);

                                if (!(color.Equals(Color.Empty)))
                                {
                                    printPanel.BackColor = color;
                                }

                                bufferGraphics.Clear(printPanel.BackColor);

                                if (image != null)
                                {
                                    Image img = image;
                                    switch (imageLayout.ToUpper())
                                    {
                                        case "TILE":
                                            TextureBrush tileBrush = new TextureBrush(img, System.Drawing.Drawing2D.WrapMode.Tile);
                                            bufferGraphics.FillRectangle(tileBrush, 0, 0, printPanel.Size.Width, printPanel.Size.Height);
                                            tileBrush.Dispose();
                                            break;

                                        case "STRETCH":
                                            bufferGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                                            bufferGraphics.DrawImage(img, 0, 0, printPanel.Size.Width, printPanel.Size.Height);
                                            bufferGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Default;
                                            break;

                                        case "CENTER":
                                            int centerX = (printPanel.Size.Width / 2) - (img.Size.Width / 2);
                                            int centerY = (printPanel.Size.Height / 2) - (img.Size.Height / 2);
                                            bufferGraphics.DrawImage(img, centerX, centerY);
                                            break;

                                        default:
                                            bufferGraphics.DrawImage(img, 0, 0);
                                            break;
                                    }
                                }

                                foreach (Control control in pageControls)
                                {
                                    if (control is DragableGroupBox)
                                    {
                                        Pen pen = new Pen(Color.Black);
                                        Point ul = control.Location;
                                        Point ur = new Point(control.Location.X + control.Width, control.Location.Y);
                                        Point ll = new Point(control.Location.X, control.Location.Y + control.Height);
                                        Point lr = new Point(control.Location.X + control.Width, control.Location.Y + control.Height);
                                        bufferGraphics.DrawLine(pen, ul, ur);
                                        bufferGraphics.DrawLine(pen, ur, lr);
                                        bufferGraphics.DrawLine(pen, lr, ll);
                                        bufferGraphics.DrawLine(pen, ll, ul);
                                    }
                                }

                                bufferGraphics.DrawImage(b, 0, 0);
                                bufferBitmap = b;
                                printPanel.BackgroundImage = b;
                            }
                            catch
                            {
                                bufferBitmap.Dispose();
                                graphics.Dispose();
                                printPanel.Dispose();
                                pageImageList = null;
                                return false;
                            }
                        }
                    }

                    foreach (Control control in pageControls)
                    {
                        if (control is DragableGroupBox)
                        {
                            Label label = new Label();
                            label.Width = control.Width;
                            label.Text = control.Text;
                            Size textSize = TextRenderer.MeasureText(graphics, label.Text, label.Font);
                            label.Left = control.Left + 12;
                            label.Top = control.Top - textSize.Height / 2;
                            label.Width = textSize.Width + 12;
                            label.Font = control.Font;
                            label.AutoSize = true;
                            printPanel.Controls.Add(label);
                        }
                    }

                    if (bufferBitmap != null)
                    {
                        graphics.DrawImage(bufferBitmap, 0, 0);
                    }

                    try
                    {
                        memoryImage = new Bitmap(printPanel.Width, printPanel.Height, graphics);
                        printPanel.DrawToBitmap(memoryImage, new Rectangle(0, 0, printPanel.Width, printPanel.Height));
                        printPanel.Dispose();
                        pageImageList.Add(memoryImage.Clone());
                    }
                    catch
                    {
                        bufferBitmap.Dispose();
                        graphics.Dispose();
                        printPanel.Dispose();
                        pageImageList = null;
                        memoryImage.Dispose();
                        return false;
                    }
                }
            }
            catch
            {
                memoryImage.Dispose();
                pageImageList = null;
                return false;
            };

            return true;
        }
예제 #13
0
        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();
        }
예제 #14
0
        private void SaveSnapshot()
        {
            PagePanel.BackgroundImageLayout = ImageLayout.None;
            if (PagePanel.Size.Width > 0 && PagePanel.Size.Height > 0)
            {
                Bitmap b = new Bitmap(PagePanel.Size.Width, PagePanel.Size.Height);
                this.bufferGraphics = Graphics.FromImage(b);
                PagePanel.BackColor = makeViewForm.CurrentBackgroundColor;
                this.bufferGraphics.Clear(PagePanel.BackColor);
                if (makeViewForm.CurrentBackgroundImage != null)
                {
                    Image img = makeViewForm.CurrentBackgroundImage;
                    switch (makeViewForm.CurrentBackgroundImageLayout.ToUpper())
                    {
                        case "TILE":
                            TextureBrush tileBrush = new TextureBrush(img, System.Drawing.Drawing2D.WrapMode.Tile);
                            bufferGraphics.FillRectangle(tileBrush, 0, 0, PagePanel.Size.Width, PagePanel.Size.Height);
                            tileBrush.Dispose();
                            break;

                        case "STRETCH":
                            bufferGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                            bufferGraphics.DrawImage(img, 0, 0, PagePanel.Size.Width, PagePanel.Size.Height);
                            bufferGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Default;
                            break;

                        case "CENTER":
                            int centerX = (this.PagePanel.Size.Width - img.Width) / 2;
                            int centerY = (this.PagePanel.Size.Height - img.Height) / 2;
                            bufferGraphics.DrawImage(img, centerX, centerY);
                            break;

                        default:
                            bufferGraphics.DrawImage(img, 0, 0);
                            break;
                    }
                }
                if (config.Settings.ShowGrid)
                {
                    this.DrawGrid(b);
                }
                bufferGraphics.DrawImage(b, 0, 0);
                bufferBitmap = b;
                PagePanel.BackgroundImage = b;
            }
        }
예제 #15
0
        protected virtual void DrawButtonState(Graphics g, ImageAttributes ia)
        {
            TextureBrush tb;

            // Draw the left and right endcaps
            g.DrawImage(imgLeft, rcLeft, 0, 0,
                imgLeft.Width, imgLeft.Height, GraphicsUnit.Pixel, ia);

            g.DrawImage(imgRight, rcRight, 0, 0,
                imgRight.Width, imgRight.Height, GraphicsUnit.Pixel, ia);

            // Draw the middle
            tb = new TextureBrush(imgFill,
                new Rectangle(0, 0, imgFill.Width, imgFill.Height), ia);
            tb.WrapMode = WrapMode.Tile;

            g.FillRectangle(tb, imgLeft.Width, 0,
                this.Width - (imgLeft.Width + imgRight.Width),
                imgFill.Height);

            tb.Dispose();
        }
예제 #16
0
    public LayeredImage(Int32 width, Int32 height)
    {
      _width = width;
      _height = height;
      _layers = new Layers(this);

      // checker board brush

      _checkerboard = new Bitmap(32, 32, PixelFormat.Format24bppRgb);
      Color darkgray = Color.FromArgb(102,102,102);
      Color lightgray = Color.FromArgb(153,153,153);
      for (Int32 i = 0; i < 32; i++) 
      {
        for (Int32 j = 0; j < 32; j++) 
        {
          if ((i < 16 && j < 16) || (i >= 16 && j >= 16))
            _checkerboard.SetPixel(j, i, lightgray);
          else
            _checkerboard.SetPixel(j, i, darkgray);
        }
      }

      // background layer

      Layer bglayer = _layers.Add();
      Graphics g = Graphics.FromImage(bglayer._bitmap._bitmap);
      TextureBrush brush = new TextureBrush(_checkerboard);
      g.FillRectangle(brush, 0, 0, _width, _height);
      brush.Dispose();
      g.Dispose();
    }
예제 #17
0
 private void DrawBackgroundImage(Graphics gr)
 {
     if (this.m_bmpBackground != null)
     {
         if (this.m_StretchBackgroundImage)
         {
             Rectangle srcRect = new Rectangle(0, 0, this.m_bmpBackground.Width, this.m_bmpBackground.Height);
             gr.DrawImage(this.m_bmpBackground, base.ClientRectangle, srcRect, GraphicsUnit.Pixel);
         }
         else
         {
             TextureBrush brush = new TextureBrush(this.m_bmpBackground);
             gr.FillRectangle(brush, base.ClientRectangle);
             brush.Dispose();
             brush = null;
         }
     }
 }
예제 #18
0
        private void SaveSnapshot()
        {
            if ((mainFrm.CurrentBackgroundImage==null) && (mainFrm.CurrentBackgroundColor.Equals(Color.Empty)))
            {
                canvasPanel.BackColor = Color.White;
            }
            else
            {
                canvasPanel.BackgroundImageLayout = ImageLayout.None;
                if (canvasPanel.Size.Width > 0 && canvasPanel.Size.Height > 0)
                {
                    Bitmap b = new Bitmap(canvasPanel.Size.Width, canvasPanel.Size.Height);
                    this.bufferGraphics = Graphics.FromImage(b);

                    if(!(mainFrm.CurrentBackgroundColor.Equals(Color.Empty)))
                    {
                        canvasPanel.BackColor = mainFrm.CurrentBackgroundColor;
                    }
                    this.bufferGraphics.Clear(canvasPanel.BackColor);
                    if (mainFrm.CurrentBackgroundImage != null )
                    {
                        Image img = mainFrm.CurrentBackgroundImage;
                        switch (mainFrm.CurrentBackgroundImageLayout.ToUpper())
                        {
                            case "TILE":
                                TextureBrush tileBrush = new TextureBrush(img, System.Drawing.Drawing2D.WrapMode.Tile);
                                bufferGraphics.FillRectangle(tileBrush, 0, 0, canvasPanel.Size.Width, canvasPanel.Size.Height);
                                tileBrush.Dispose();
                                break;

                            case "STRETCH":
                                bufferGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                                bufferGraphics.DrawImage(img, 0, 0, canvasPanel.Size.Width, canvasPanel.Size.Height);
                                bufferGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Default;
                                break;

                            case "CENTER":
                                int centerX = (canvasPanel.Size.Width / 2) - (img.Size.Width / 2);
                                int centerY = (canvasPanel.Size.Height / 2) - (img.Size.Height / 2);
                                bufferGraphics.DrawImage(img, centerX, centerY);
                                break;

                            default:
                                bufferGraphics.DrawImage(img, 0, 0);
                                break;
                        }
                    }

                    bufferGraphics.DrawImage(b, 0, 0);
                    bufferBitmap = b;
                    canvasPanel.BackgroundImage = b;
                }
            }
        }
예제 #19
0
        /// <summary>
        /// Instructs the drawing code to fill the specified path with the specified image.
        /// </summary>
        /// <param name="g">The Graphics device to draw to</param>
        /// <param name="gp">The GraphicsPath to fill</param>
        public override void FillPath(Graphics g, GraphicsPath gp)
        {
            if (_picture == null) return;
            if (_scale.X == 0 || _scale.Y == 0) return;
            if (_scale.X * _picture.Width * _scale.Y * _picture.Height > 8000 * 8000) return; // The scaled image is too large, will cause memory exceptions.
            Bitmap scaledBitmap = new Bitmap((int)(_picture.Width * _scale.X), (int)(_picture.Height * _scale.Y));
            Graphics scb = Graphics.FromImage(scaledBitmap);
            scb.DrawImage(_picture, new Rectangle(0, 0, scaledBitmap.Width, scaledBitmap.Height), new Rectangle(0, 0, _picture.Width, _picture.Height), GraphicsUnit.Pixel);

            TextureBrush tb = new TextureBrush(scaledBitmap, _wrapMode);
            tb.RotateTransform(-(float)_angle);
            g.FillPath(tb, gp);
            tb.Dispose();
            scb.Dispose();
            base.FillPath(g, gp);
        }
예제 #20
0
        //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);
            //}
        }
예제 #21
0
파일: WordBoard.cs 프로젝트: h87kg/wordmake
 private void redrawShowBitmap()
 {
     if (showBitmap == null)
         return;
     int ib = 0;
     int w = width, h = height;
     Graphics g = Graphics.FromImage(showBitmap);
     Pen fp = new Pen(frameColor, multiple / 4);
     fp.Alignment = PenAlignment.Inset;
     Brush Fbrush = new SolidBrush(this.ForeColor);
     Brush Bbrush = new SolidBrush(this.lcdColor);
     int lsize = multiple / 4;
     Rectangle Bdr = new Rectangle(0, 0, multiple - lsize, multiple - lsize);
     Rectangle fr = new Rectangle(0, 0, multiple * w, multiple * h);
     Bitmap rectBitmap = new Bitmap(multiple, multiple);
     Graphics mapg = Graphics.FromImage(rectBitmap);
     mapg.Clear(this.BackColor);
     mapg.FillRectangle(Bbrush, Bdr);
     //mapg.Dispose();
     TextureBrush textureB = new TextureBrush(rectBitmap);
     g.FillRectangle(textureB, this.DisplayRectangle);
     textureB.Dispose();
     //mapg.FillRectangle(Fbrush, Bdr);
     //textureB = new TextureBrush(rectBitmap);
     mapg.Dispose();
     rectBitmap.Dispose();
     g.SmoothingMode = SmoothingMode.HighSpeed;
     for (int istr = 0; istr < this.Text.Length; istr++)
     {
         if (!DisplayRectangle.Contains(fr.Location))
         {
             break;
         }
         BitArray bita = this.GetCharMap(this.Text[istr]);
         for (int i = 0; i < h; i++)
         {
             for (int k = 0; k < w; k++)
             {
                 if (bita[ib++])
                 {
                     g.FillRectangle(Fbrush, Bdr);
                 }
                 Bdr.X += multiple;
             }
             Bdr.X -= w * multiple;
             Bdr.Y += multiple;
         }
         g.DrawRectangle(fp, fr);
         fr.X = fr.Right;
         if (!DisplayRectangle.Contains(new Point(fr.Right, fr.Y)))
         {
             fr.X = 0;
             fr.Y = fr.Bottom;
         }
         Bdr.Location = fr.Location;
         ib = 0;
     }
     fp.Dispose();
     Fbrush.Dispose();
     Bbrush.Dispose();
 }
예제 #22
0
        public static void FillTexturedRectangle(Rectangle rectangle, Image texture, bool drawGradient, Graphics graphics)
        {
            if (rectangle.Width == 0 || rectangle.Height == 0)
                return;

            TextureBrush textureBrush = new TextureBrush(texture, WrapMode.Tile);
            graphics.FillRectangle(textureBrush, rectangle);
            textureBrush.Dispose();

            if (drawGradient == true)
            {
                Brush gradientBrush = new LinearGradientBrush(rectangle, Color.FromArgb(96, Color.White), Color.FromArgb(160, Color.Black), 90.0f);
                graphics.FillRectangle(gradientBrush, rectangle);
                gradientBrush.Dispose();
            }
        }
예제 #23
0
        /// <summary>
        /// Draws a graph of friends into a Bitmap
        /// </summary>
        /// <param name="graph">Friend connection graf</param>
        /// <param name="srcDir">Where to take user profile picture thumbnails from</param>
        /// <param name="settings">Settings - when left blank, default settings are used</param>
        /// <param name="worker">To report the progress</param>
        /// <returns>Bitmap with the graph</returns>
        private static Bitmap DrawGraph(FriendGraph graph, string imageDir, BackgroundWorker worker = null)
        {
            Bitmap bmp = new Bitmap(GraphSettings.ImageWidth, GraphSettings.ImageHeight);
            Graphics g = Graphics.FromImage(bmp);

            g.Clear(Color.White);
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            // if we have the autosize option on, we find the maximum number of friends
            int maxFriends = 0;

            // we draw lines connecting friends
            int i = 0;
            List<Friend> done = new List<Friend>(); // so we dont draw lines both ways
            foreach(KeyValuePair<Friend, List<Friend>> pair in graph) {
                if(worker != null && worker.CancellationPending)
                    throw new InterruptedException();

                Pen pen = new Pen(Color.FromArgb(64, 0, 0, 0), 1);

                foreach(Friend f in pair.Value) {
                    if(!done.Contains(f))
                        g.DrawLine(pen, pair.Key.coordinates, f.coordinates);
                }

                if(pair.Value.Count > maxFriends)
                    maxFriends = pair.Value.Count;

                pen.Dispose();

                done.Add(pair.Key);

                if(worker != null)
                    worker.ReportProgress(Math.Min(99, ++i * 50 / graph.Count));
            }

            int photoSize = GraphSettings.PhotoSize;

            // if we have the autosize option on, we would like bigger pictures be on top of smaller
            // we sort them by their friend count asc
            if(GraphSettings.AutoSize) {
                done.Sort((x, y) =>
                {
                    if(graph[x].Count < graph[y].Count)
                        return -1;
                    else if(graph[y].Count < graph[x].Count)
                        return 1;

                    return 0;
                });
            }

            // we draw profile photos inside
            foreach(Friend f in done) {
                if(worker != null && worker.CancellationPending)
                    throw new InterruptedException();

                Image photo = Image.FromFile(imageDir + "/photos/" + f.id + ".jpg");

                if(GraphSettings.AutoSize) {
                    photoSize = (int) (15 + 35 * ((float) graph[f].Count / (float) maxFriends));
                }

                if(GraphSettings.PhotoShape == Shape.Circle) { // we must crop circle out of the profile picture

                    // we create brush
                    TextureBrush brush = new TextureBrush(photo, WrapMode.Clamp);

                    // resize the brush
                    brush.ScaleTransform(((float) photoSize) / 50f,
                                         ((float) photoSize) / 50f,
                                         MatrixOrder.Append);

                    // we reset the brush starting position
                    brush.TranslateTransform(f.coordinates.X - photoSize / 2,
                                             f.coordinates.Y - photoSize / 2, MatrixOrder.Append);

                    // and fill a circle with it
                    g.FillEllipse(brush,
                                  f.coordinates.X - photoSize / 2,
                                  f.coordinates.Y - photoSize / 2,
                                  photoSize,
                                  photoSize);

                    brush.Dispose();

                } else { // square - just draw the image
                    g.DrawImage(photo,
                                f.coordinates.X - photoSize / 2,
                                f.coordinates.Y - photoSize / 2,
                                photoSize,
                                photoSize);
                }

                photo.Dispose();

                if(worker != null)
                    worker.ReportProgress(Math.Min(99, ++i * 50 / graph.Count));
            }

            g.Dispose();

            return bmp;
        }
예제 #24
0
        public static void RoundImage(Image bitmap, int roundedDia)
        {
            Brush brush = new TextureBrush(bitmap);
            Graphics g = Graphics.FromImage(bitmap);
            g.Clear(Color.White);

            Genetibase.UI.NuGenImageWorks.Grpahics.FillRoundedRectangle(g, brush, new Rectangle(0, 0, bitmap.Width, bitmap.Height), 30);

            g.Dispose();
            brush.Dispose();

            Rounded = true;
        }
예제 #25
0
 private void DrawCheckBackground(Graphics g, Rectangle bounds)
 {
     Pen controlDark = SystemPens.ControlDark;
     Pen controlLightLight = SystemPens.ControlLightLight;
     Bitmap bitmap = new Bitmap(0x10, 0x10);
     for (int i = 0; i < 0x10; i += 2)
     {
         for (int j = 0; j < 0x10; j += 2)
         {
             bitmap.SetPixel(i, j, SystemColors.ControlLightLight);
         }
     }
     Brush brush = new TextureBrush(bitmap);
     g.FillRectangle(SystemBrushes.Menu, bounds);
     g.FillRectangle(brush, bounds);
     g.DrawLine(controlDark, bounds.X, bounds.Y, (bounds.X + bounds.Width) - 1, bounds.Y);
     g.DrawLine(controlDark, bounds.X, bounds.Y, bounds.X, (bounds.Y + bounds.Height) - 1);
     g.DrawLine(controlLightLight, bounds.X, (bounds.Y + bounds.Height) - 1, (bounds.X + bounds.Width) - 1, (bounds.Y + bounds.Height) - 1);
     g.DrawLine(controlLightLight, (int) ((bounds.X + bounds.Width) - 1), (int) ((bounds.Y + bounds.Height) - 1), (int) ((bounds.X + bounds.Width) - 1), (int) (bounds.Y + 1));
     bitmap.Dispose();
     brush.Dispose();
 }
예제 #26
0
        public static void RoundImageTransparent(Image bitmap, int roundedDia)
        {
            Brush brush = new TextureBrush(bitmap);
            Graphics g = Graphics.FromImage(bitmap);
            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.Clear(Color.Transparent);

            Genetibase.UI.NuGenImageWorks.Grpahics.FillRoundedRectangle(g, brush, new Rectangle(0, 0, bitmap.Width, bitmap.Height), 30);

            g.Dispose();
            brush.Dispose();

            Rounded = true;
        }
예제 #27
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            // Get the graphics object. We need something to draw with

            Graphics g = e.Graphics;
            // Create tiled brushes for the shadow on the right and at the bottom.

            TextureBrush shadowRightBrush = new TextureBrush(shadowRight, WrapMode.Tile);
            TextureBrush shadowDownBrush = new TextureBrush(shadowDown, WrapMode.Tile);

            // Translate (move) the brushes so the top or left of the image matches the top or left of the

            // area where it's drawed. If you don't understand why this is necessary, comment it out.

            // Hint: The tiling would start at 0,0 of the control, so the shadows will be offset a little.

            shadowDownBrush.TranslateTransform(0, Height - shadowSize);
            shadowRightBrush.TranslateTransform(Width - shadowSize, 0);

            // Define the rectangles that will be filled with the brush.

            // (where the shadow is drawn)

            Rectangle shadowDownRectangle = new Rectangle(
                shadowSize + shadowMargin,                      // X

                Height - shadowSize,                            // Y

                Width - (shadowSize * 2 + shadowMargin),        // width (stretches)

                shadowSize                                      // height

                );

            Rectangle shadowRightRectangle = new Rectangle(
                Width - shadowSize,                             // X

                shadowSize + shadowMargin,                      // Y

                shadowSize,                                     // width

                Height - (shadowSize * 2 + shadowMargin)        // height (stretches)

                );

            // And draw the shadow on the right and at the bottom.

            g.FillRectangle(shadowDownBrush, shadowDownRectangle);
            g.FillRectangle(shadowRightBrush, shadowRightRectangle);

            // Now for the corners, draw the 3 5�5 pixel images.

            g.DrawImage(shadowTopRight, new Rectangle(Width - shadowSize, shadowMargin, shadowSize, shadowSize));
            g.DrawImage(shadowDownRight, new Rectangle(Width - shadowSize, Height - shadowSize, shadowSize, shadowSize));
            g.DrawImage(shadowDownLeft, new Rectangle(shadowMargin, Height - shadowSize, shadowSize, shadowSize));

            // Fill the area inside with the color in the PanelColor property.

            // 1 pixel is added to everything to make the rectangle smaller.

            // This is because the 1 pixel border is actually drawn outside the rectangle.

             Rectangle fullRectangle = new Rectangle(
                1,                                              // X

                1,                                              // Y

                Width - (shadowSize + 2),                       // Width

                Height - (shadowSize + 2)                       // Height

                );

            if (PanelColor != null)
            {
                SolidBrush bgBrush = new SolidBrush(_panelColor);
                g.FillRectangle(bgBrush, fullRectangle);
            }

            // Draw a nice 1 pixel border it a BorderColor is specified

            if (_borderColor != null)
            {
                Pen borderPen = new Pen(BorderColor);
                g.DrawRectangle(borderPen, fullRectangle);
            }

                        // Memory efficiency

            shadowDownBrush.Dispose();
            shadowRightBrush.Dispose();

            shadowDownBrush = null;
            shadowRightBrush = null;
        }
예제 #28
0
		public void Dispose_Dispose ()
		{
			TextureBrush t = new TextureBrush (image);
			t.Dispose ();
			t.Dispose ();
		}
 private static Pen GetFocusPen(Color backColor, bool odds)
 {
     if (((focusPen == null) || ((focusPenColor.GetBrightness() <= 0.5) && (backColor.GetBrightness() <= 0.5))) || !focusPenColor.Equals(backColor))
     {
         if (focusPen != null)
         {
             focusPen.Dispose();
             focusPen = null;
             focusPenInvert.Dispose();
             focusPenInvert = null;
         }
         focusPenColor = backColor;
         Bitmap bitmap = new Bitmap(2, 2);
         Color transparent = Color.Transparent;
         Color black = Color.Black;
         if (backColor.GetBrightness() <= 0.5)
         {
             transparent = black;
             black = InvertColor(backColor);
         }
         else if (backColor == Color.Transparent)
         {
             transparent = Color.White;
         }
         bitmap.SetPixel(1, 0, black);
         bitmap.SetPixel(0, 1, black);
         bitmap.SetPixel(0, 0, transparent);
         bitmap.SetPixel(1, 1, transparent);
         Brush brush = new TextureBrush(bitmap);
         focusPen = new Pen(brush, 1f);
         brush.Dispose();
         bitmap.SetPixel(1, 0, transparent);
         bitmap.SetPixel(0, 1, transparent);
         bitmap.SetPixel(0, 0, black);
         bitmap.SetPixel(1, 1, black);
         brush = new TextureBrush(bitmap);
         focusPenInvert = new Pen(brush, 1f);
         brush.Dispose();
         bitmap.Dispose();
     }
     if (!odds)
     {
         return focusPenInvert;
     }
     return focusPen;
 }
예제 #30
0
        public static void DrawShadow(Graphics g,Rectangle r)
        {

            r.Offset(shadowSize,shadowSize);
            TextureBrush shadowRightBrush = new TextureBrush(shadowRight, WrapMode.Tile);
            TextureBrush shadowDownBrush = new TextureBrush(shadowDown, WrapMode.Tile);

            // Translate (move) the brushes so the top or left of the image matches the top or left of the
            // area where it's drawed. If you don't understand why this is necessary, comment it out. 
            // Hint: The tiling would start at 0,0 of the control, so the shadows will be offset a little.
            //shadowDownBrush.TranslateTransform(0, r.Height - shadowSize);
            //shadowRightBrush.TranslateTransform(r.Width - shadowSize, 0);
            shadowDownBrush.TranslateTransform(0,r.Height + r.Y - shadowSize);
            shadowRightBrush.TranslateTransform(r.Width + r.X - shadowSize, 0);

            // Define the rectangles that will be filled with the brush.
            // (where the shadow is drawn)
       
            Rectangle shadowDownRectangle = new Rectangle(
                r.X + shadowSize + shadowMargin,                      // X
                r.Y + r.Height - shadowSize,                            // Y
                r.Width - (2 * shadowSize + shadowMargin),        // width (stretches)
                shadowSize                                      // height
                );


            Rectangle shadowRightRectangle = new Rectangle(
                r.Width - shadowSize + r.X,                             // X
                shadowSize + shadowMargin + r.Y,                      // Y
                shadowSize,                                     // width
                r.Height - (shadowSize * 2 + shadowMargin)        // height (stretches)
                );

            // And draw the shadow on the right and at the bottom.
            g.FillRectangle(shadowDownBrush, shadowDownRectangle);
            g.FillRectangle(shadowRightBrush, shadowRightRectangle);

            // Now for the corners, draw the 3 5x5 pixel images.
            g.DrawImage(shadowTopRight, new Rectangle(r.Width - shadowSize+r.X, shadowMargin+r.Y, shadowSize, shadowSize));
            g.DrawImage(shadowDownRight, new Rectangle(r.Width - shadowSize+r.X, r.Height - shadowSize+r.Y, shadowSize, shadowSize));
            g.DrawImage(shadowDownLeft, new Rectangle(shadowMargin+r.X, r.Height - shadowSize+r.Y, shadowSize, shadowSize));

        
            // Memory efficiency
            shadowDownBrush.Dispose();
            shadowRightBrush.Dispose();

            shadowDownBrush = null;
            shadowRightBrush = null;

        }