// This method draws a border around the GridStrip control. protected override void OnRenderToolStripBorder( ToolStripRenderEventArgs e) { base.OnRenderToolStripBorder(e);
if (e.ToolStrip is ToolStripDropDown) //过滤,根据需要可能还有更多的过滤 return;
using (Pen pen = new Pen(SystemColors.ButtonShadow)) { if (m_DrawBorderMode == DrawBorderMode.TopAndBottom || m_DrawBorderMode == DrawBorderMode.TopOnly) e.Graphics.DrawLine(pen, e.AffectedBounds.X, e.AffectedBounds.Y, e.AffectedBounds.Width, e.AffectedBounds.Y); if (m_DrawBorderMode == DrawBorderMode.TopAndBottom || m_DrawBorderMode == DrawBorderMode.BottomOnly) e.Graphics.DrawLine(pen, e.AffectedBounds.X, e.AffectedBounds.Height - 1, e.AffectedBounds.Width, e.AffectedBounds.Height - 1); } }
if (e.ToolStrip is ToolStripDropDown) //过滤,根据需要可能还有更多的过滤 return;
//SystemColors.ControlLightLight, //SystemColors.InactiveBorder, Color gradientEnd = this.ToolStripGradientEnd; float angle = 0; if (m_BackgroundGradientStyle == BackgroundGradientStyle.Vertical) angle = 90; if (m_BackgroundGradientStyle == BackgroundGradientStyle.None) gradientEnd = this.ToolStripGradientBegin;
if (this.backgroundBrush == null) { this.backgroundBrush = new LinearGradientBrush( e.ToolStrip.ClientRectangle, this.ToolStripGradientBegin, gradientEnd, angle, true); }
// Paint the GridStrip control's background. e.Graphics.FillRectangle( this.backgroundBrush, e.AffectedBounds);
if (e.ToolStrip.GripStyle == ToolStripGripStyle.Visible) { ControlPaint.DrawBorder3D(e.Graphics, new Rectangle(3, 3, 2, e.ToolStrip.Height - 6), Border3DStyle.Etched, Border3DSide.Left | Border3DSide.Right); ControlPaint.DrawBorder3D(e.Graphics, new Rectangle(7, 3, 2, e.ToolStrip.Height - 6), Border3DStyle.Etched, Border3DSide.Left | Border3DSide.Right); }
//显示水印。 if (m_WatermarkImage != null) { Point position = Point.Empty; int top = borderPadding; int left = 0; int width = 0; int height = 0; if (m_WatermarkImage.Height > e.ToolStrip.Height - borderPadding * 2) { //重新定义图片的显示宽高 double rate = (double)m_WatermarkImage.Width / (double)m_WatermarkImage.Height; height = e.ToolStrip.Height - borderPadding * 2; width = Convert.ToInt32(rate * height); } else { width = m_WatermarkImage.Width; height = m_WatermarkImage.Height; top = (e.ToolStrip.Height - height) / 2;
} left = e.ToolStrip.Width - width - borderPadding * 2;
position = new Point(left, top); Rectangle rect = new Rectangle(left, top, width, height); e.Graphics.DrawImage(m_WatermarkImage, rect, new Rectangle(0, 0, m_WatermarkImage.Width, m_WatermarkImage.Height), GraphicsUnit.Pixel); } }
// This method handles the RenderGrip event. protected override void OnRenderGrip(ToolStripGripRenderEventArgs e) { //DrawTitleBar( // e.Graphics, // new Rectangle(0, 0, e.ToolStrip.Width, e.ToolStrip.Height)); //ControlPaint.DrawBorder3D(e.Graphics, new Rectangle(0, 3, 2, e.ToolStrip.Height - 6), Border3DStyle.RaisedInner); //ControlPaint.DrawBorder3D(e.Graphics, new Rectangle(3, 3, 2, e.ToolStrip.Height - 6), Border3DStyle.RaisedInner); }
}
/// <summary> /// 为保存图片的状态而设 /// </summary> internal class EtyImageState { public int InitImageKey { get { if (m_InitImage == null) return -1; else return m_InitImage.GetHashCode(); } }
private Image m_InitImage;
public Image InitImage { get { return m_InitImage; } set { m_InitImage = value; } }
public int LightImageKey { get { if (m_LightImage == null) return -1; else return m_LightImage.GetHashCode(); } }
private Image m_LightImage;
public Image LightImage { get { return m_LightImage; } set { m_LightImage = value; } }
public static class ImageTool { /// <summary> /// 根据字符串生成图片。 /// </summary> /// <param name="data"></param> /// <returns></returns> public static Bitmap DeserializeFromBase64(string data) { // Decode the string and create a memory stream // on the decoded string data. MemoryStream stream = new MemoryStream(Convert.FromBase64String(data));
// Create a new bitmap from the stream. Bitmap b = new Bitmap(stream);
return b; } //图片 转为 base64编码的文本 public static string ImgToBase64String(Image bmp) { MemoryStream ms = new MemoryStream(); bmp.Save(ms, bmp.RawFormat); byte[] arr = new byte[ms.Length]; ms.Position = 0; ms.Read(arr, 0, (int)ms.Length); ms.Close(); String strbase64 = Convert.ToBase64String(arr); return strbase64; }
/// <summary> /// 图片增亮。 /// </summary> /// <param name="img"></param> /// <returns></returns> public static Image Brightness(Image img, int brightValue) { int percent = brightValue; Single v = 0.006F * percent; Single[][] matrix = { new Single[] { 1, 0, 0, 0, 0 }, new Single[] { 0, 1, 0, 0, 0 }, new Single[] { 0, 0, 1, 0, 0 }, new Single[] { 0, 0, 0, 1, 0 }, new Single[] { v, v, v, 0, 1 } }; System.Drawing.Imaging.ColorMatrix cm = new System.Drawing.Imaging.ColorMatrix(matrix); System.Drawing.Imaging.ImageAttributes attr = new System.Drawing.Imaging.ImageAttributes(); attr.SetColorMatrix(cm); //Image tmp //Image tmp = (Image)img.Clone(); Bitmap tmp = new Bitmap(img); Graphics g = Graphics.FromImage(tmp); try { Rectangle destRect = new Rectangle(0, 0, img.Width, img.Height); g.DrawImage(tmp, destRect, 0, 0, tmp.Width, tmp.Height, GraphicsUnit.Pixel, attr); } finally { g.Dispose(); }
return tmp;
}
//处理不了透明的背景 /// <summary> /// 制作水印图片 /// </summary> /// <param name="iTheImage">要制作水印的图片</param> /// <param name="width">制作水印的宽</param> /// <param name="height">制作水印的高</param> /// <returns></returns> public static Bitmap WatermarkImage(Bitmap iTheImage, int width, int height) { //Bitmap watermark = new Bitmap(width, height, // PixelFormat.Format24bppRgb); Bitmap watermark = new Bitmap(iTheImage);