private void printDocument_ImageWaterMark(object sender, System.Drawing.Printing.PrintPageEventArgs e) { System.Drawing.Rectangle rect = new System.Drawing.Rectangle(280, 420, 700, 700); Graphics g = e.Graphics; System.Drawing.Image StudentImage = pictureBox3.Image; // Create image attributes and set large gamma. System.Drawing.Imaging.ImageAttributes imageAttr = new System.Drawing.Imaging.ImageAttributes(); imageAttr.SetGamma(0.2f, System.Drawing.Imaging.ColorAdjustType.Bitmap); //imageAttr.SetColorKey(Color.White, Color.White); // Draw adjusted image to screen. g.DrawImage(StudentImage, rect, 10, 10, 700, 700, GraphicsUnit.Pixel, imageAttr); printNumber++; }
protected override void OnPaint(PaintEventArgs e) { if (_image != null) { var attr = new System.Drawing.Imaging.ImageAttributes(); int top = Top; int bottom = Top + Height; int left = Left; int right = Left + Width; attr.SetGamma(gamma); // slight change to how they drew it e.Graphics.DrawImage(_image, new Rectangle((Width / 2) - (_image.Width / 2), (Height / 2) - (_image.Height / 2), _image.Width, _image.Height), 0, 0, _image.Width, _image.Height, GraphicsUnit.Pixel, attr); } }
protected override void OnPaint(PaintEventArgs e) { if (_image == null) { return; } var attr = new System.Drawing.Imaging.ImageAttributes(); attr.SetGamma(gamma); // slight change to how they drew it int width = (int)(_image.Width * scale); int height = (int)(_image.Height * scale); e.Graphics.DrawImage(_image, new Rectangle((Width / 2) - (width / 2), (Height / 2) - (height / 2), width, height), 0, 0, _image.Width, _image.Height, GraphicsUnit.Pixel, attr); }
// </snippet3> // Snippet for: M:System.Drawing.Imaging.ImageAttributes.SetGamma(System.Single) // <snippet4> private void SetGammaExample(PaintEventArgs e) { // Create an Image object from the file Camera.jpg, and draw it to // the screen. Image myImage = Image.FromFile("Camera.jpg"); e.Graphics.DrawImage(myImage, 20, 20); // Create an ImageAttributes object and set the gamma to 2.2. System.Drawing.Imaging.ImageAttributes imageAttr = new System.Drawing.Imaging.ImageAttributes(); imageAttr.SetGamma(2.2f); // Draw the image with gamma set to 2.2. Rectangle rect = new Rectangle(250, 20, 200, 200); e.Graphics.DrawImage(myImage, rect, 0, 0, 200, 200, GraphicsUnit.Pixel, imageAttr); }
// Adjust the gamma. Useful values are between .1 and 3, neutral is 1 // WORKS WELL private static System.Drawing.Bitmap AdjustGamma(System.Drawing.Image image, float gamma) { if (gamma <= 0) { // Just in case... gamma = .1f; } // Set the ImageAttributes object's gamma value. using (System.Drawing.Imaging.ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes()) { attributes.SetGamma(gamma); // Draw the image onto the new bitmap // while applying the new gamma value. System.Drawing.Point[] points = { new System.Drawing.Point(0, 0), new System.Drawing.Point(image.Width, 0), new System.Drawing.Point(0, image.Height), }; System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, image.Width, image.Height); // Make the result bitmap. System.Drawing.Bitmap bm = new System.Drawing.Bitmap(image.Width, image.Height); using (System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bm)) { gr.DrawImage(image, points, rect, System.Drawing.GraphicsUnit.Pixel, attributes); } // Return the result. return(bm); } }
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(); }
protected override void OnPaint(PaintEventArgs e) { if (_image != null) { var attr = new System.Drawing.Imaging.ImageAttributes(); int top = Top; int bottom = Top + Height; int left = Left; int right = Left + Width; attr.SetGamma(gamma); // slight change to how they drew it e.Graphics.DrawImage(_image, new Rectangle((Width / 2) - (_image.Width / 2), (Height / 2) - (_image.Height / 2), _image.Width, _image.Height), 0, 0, _image.Width, _image.Height, GraphicsUnit.Pixel, attr); } }
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(); }
private void showInputRange() { Bitmap bmp = UIControl.captureScreen(); Bitmap newBmp = new Bitmap(bmp.Width, bmp.Height); Graphics g = Graphics.FromImage(newBmp); System.Drawing.Imaging.ImageAttributes ia = new System.Drawing.Imaging.ImageAttributes(); ia.SetGamma((float)0.3); if (inputRange.left == inputRange.right && inputRange.up == inputRange.down) { g.DrawImage(bmp, new Point(0, 0)); } else { g.DrawImage(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, ia); } for (int y = inputRange.up; y < inputRange.down; y++) { for (int x = inputRange.left; x < inputRange.right; x++) { newBmp.SetPixel(x, y, bmp.GetPixel(x, y)); } } foreach (var pos in inputPoints) { g.FillEllipse(Brushes.Blue, new Rectangle(pos[0] - 8, pos[1] - 8, 16, 16)); } g.Dispose(); form.logWithDispose(newBmp); bmp.Dispose(); }