public override void Draw(System.Drawing.RectangleF dirtyRect) { var g = new Graphics(); // NSView does not have a background color so we just use Clear to white here g.Clear(Color.White); //RectangleF ClientRectangle = this.Bounds; RectangleF ClientRectangle = dirtyRect; // Calculate the location and size of the drawing area // within which we want to draw the graphics: Rectangle rect = new Rectangle((int)ClientRectangle.X, (int)ClientRectangle.Y, (int)ClientRectangle.Width, (int)ClientRectangle.Height); drawingRectangle = new Rectangle(rect.Location, rect.Size); drawingRectangle.Inflate(-offset, -offset); //Draw ClientRectangle and drawingRectangle using Pen: g.DrawRectangle(Pens.Red, rect); g.DrawRectangle(Pens.Black, drawingRectangle); // Draw a line from point (3,2) to Point (6, 7) // using the Pen with a width of 3 pixels: Pen aPen = new Pen(Color.Green, 3); g.DrawLine(aPen, Point2D(new PointF(3, 2)), Point2D(new PointF(6, 7))); g.PageUnit = GraphicsUnit.Inch; ClientRectangle = new RectangleF(0.5f,0.5f, 1.5f, 1.5f); aPen.Width = 1 / g.DpiX; g.DrawRectangle(aPen, ClientRectangle); aPen.Dispose(); g.Dispose(); }
public RectangleTransparent() { clearPen = new Pen(Color.FromArgb(1, 0, 0, 0)); borderDotPen = new Pen(Color.Black, 1); borderDotPen2 = new Pen(Color.White, 1); borderDotPen2.DashPattern = new float[] { 5, 5 }; penTimer = Stopwatch.StartNew(); ScreenRectangle = CaptureHelpers.GetScreenBounds(); surface = new Bitmap(ScreenRectangle.Width, ScreenRectangle.Height); gSurface = Graphics.FromImage(surface); gSurface.InterpolationMode = InterpolationMode.NearestNeighbor; gSurface.SmoothingMode = SmoothingMode.HighSpeed; gSurface.CompositingMode = CompositingMode.SourceCopy; gSurface.CompositingQuality = CompositingQuality.HighSpeed; gSurface.Clear(Color.FromArgb(1, 0, 0, 0)); StartPosition = FormStartPosition.Manual; Bounds = ScreenRectangle; Text = "ShareX - " + Resources.RectangleTransparent_RectangleTransparent_Rectangle_capture_transparent; Shown += RectangleLight_Shown; KeyUp += RectangleLight_KeyUp; MouseDown += RectangleLight_MouseDown; MouseUp += RectangleLight_MouseUp; using (MemoryStream cursorStream = new MemoryStream(Resources.Crosshair)) { Cursor = new Cursor(cursorStream); } timer = new Timer { Interval = 10 }; timer.Tick += timer_Tick; timer.Start(); }
public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) { Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert); if (applyRect.Width == 0 || applyRect.Height == 0) { // nothing to do return; } GraphicsState state = graphics.Save(); if (Invert) { graphics.SetClip(applyRect); graphics.ExcludeClip(rect); } ColorMatrix grayscaleMatrix = new ColorMatrix(new[] { new[] {.3f, .3f, .3f, 0, 0}, new[] {.59f, .59f, .59f, 0, 0}, new[] {.11f, .11f, .11f, 0, 0}, new float[] {0, 0, 0, 1, 0}, new float[] {0, 0, 0, 0, 1} }); using (ImageAttributes ia = new ImageAttributes()) { ia.SetColorMatrix(grayscaleMatrix); graphics.DrawImage(applyBitmap, applyRect, applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height, GraphicsUnit.Pixel, ia); } graphics.Restore(state); }
private void EnsureTemporaryBitmap( int width, int height ) { if( bmp != null ) { if( bmp.Width >= width && bmp.Height >= height ) { g.Clear( Color.Black ); return; } width = Math.Max( width, bmp.Width ); height = Math.Max( height, bmp.Height ); } Helpers.DisposeAndClear( ref g ); Helpers.DisposeAndClear( ref bmp ); bmp = new Bitmap( width, height, PixelFormat.Format32bppRgb ); g = Graphics.FromImage( bmp ); g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; g.Clear( Color.Black ); }
void PaintVoxel(Graphics graphics, int i, int j) { Brush brushVoxel_True = new SolidBrush(Color.FromArgb(181, 230, 29)); Brush brushVoxel_False = new SolidBrush(Color.FromArgb(240, 240, 240)); graphics.FillRectangle(VoxelsData[i, j] ? brushVoxel_True : brushVoxel_False, VoxelSize * i + 1, VoxelSize * j + 1, VoxelSize - 1, VoxelSize - 1); }
/* Draw the triangles */ public void DrawTriangles(Graphics canvas) { foreach (Triangle tri in triangles) { tri.Draw(canvas); } }
protected internal override void Paint(Graphics gr) { var hf = CandleView.BAR_WIDTH / 2; if (m_View.Kind== ViewKind.SideBySide) { var hh = Host.Height / Host.Zoom; gr.FillRectangle(Brushes.Green, this.Left, hh - m_Lay_BuyHeight, hf, m_Lay_BuyHeight); gr.FillRectangle(Brushes.Red, this.Left+hf, hh - m_Lay_SellHeight, hf, m_Lay_SellHeight); } else if (m_View.Kind== ViewKind.Stacked) { var hh = Host.Height / Host.Zoom; gr.FillRectangle(Brushes.Green, this.Left, hh - m_Lay_BuyHeight, CandleView.BAR_WIDTH, m_Lay_BuyHeight); gr.FillRectangle(Brushes.Red, this.Left, hh - m_Lay_BuyHeight-m_Lay_SellHeight, CandleView.BAR_WIDTH, m_Lay_SellHeight); } else//centered { var mid = (Host.Height / 2) / Host.Zoom; gr.FillRectangle(Brushes.Green, this.Left, mid - m_Lay_BuyHeight, CandleView.BAR_WIDTH, m_Lay_BuyHeight); gr.FillRectangle(Brushes.Red, this.Left, mid, CandleView.BAR_WIDTH, m_Lay_SellHeight); } }
public void DrawPath(Graphics g, Pen p) { if (m_points != null) { g.DrawLines(p, m_points); } }
public static void AddTag2(Graphics g, int x_pos, int y_pos, Size Canvas) { int x_scale = Canvas.Width / x_number_of_datapoints; int y_scale = Canvas.Height / y_number_of_datapoints; g.FillEllipse(tag2, (x_scale * x_pos) - diamater / 2, (y_pos * y_scale) - diamater / 2, diamater, diamater); }
public void DrawPaperSheet(Graphics graphic) { if (SingleOffset.Paper == null) { return; } var comp1 = (int)(SingleOffset.Paper.SizeH / printFormatWidth.Value) * (int)(SingleOffset.Paper.SizeW / printFormatHeight.Value); var comp2 = (int)(SingleOffset.Paper.SizeH / printFormatHeight.Value) * (int)(SingleOffset.Paper.SizeW / printFormatWidth.Value); if (comp1 > comp2) { var widthUse = (int)(SingleOffset.Paper.SizeW / printFormatHeight.Value); var heightUse = (int)(SingleOffset.Paper.SizeH / printFormatWidth.Value); var flipped = widthUse * printFormatHeight.Value > SingleOffset.Paper.SizeW || heightUse * printFormatWidth.Value > SingleOffset.Paper.SizeH; Drawing.Draw(graphic, SingleOffset.Paper.SizeW, SingleOffset.Paper.SizeH, (int)printFormatHeight.Value, (int)printFormatWidth.Value, heightUse, widthUse, false, false); usePerSheetLabel.Text = comp1 == usePerSheet.Value ? "" : string.Format("Anzahl Nutzen passt nicht.{0}Empfohlen wären {1} Nutzen.", Environment.NewLine, comp1); usePerSheetLabel.Update(); } else { var heightUse = (int)(SingleOffset.Paper.SizeH / printFormatHeight.Value); var widthUse = (int)(SingleOffset.Paper.SizeW / printFormatWidth.Value); var flipped = widthUse * printFormatWidth.Value > SingleOffset.Paper.SizeW || heightUse * printFormatHeight.Value > SingleOffset.Paper.SizeH; Drawing.Draw(graphic, SingleOffset.Paper.SizeW, SingleOffset.Paper.SizeH, (int)printFormatWidth.Value, (int)printFormatHeight.Value, widthUse, heightUse, false, false); usePerSheetLabel.Text = comp2 == usePerSheet.Value ? "" : string.Format("Anzahl Nutzen passt nicht.{0}Empfohlen wären {1} Nutzen.", Environment.NewLine, comp2); usePerSheetLabel.Update(); } }
public VisibleSurface(Graphics graphics, int wdth, int hght) : base(wdth, hght) { base.DC = graphics; base.Buffer = new Backbuffer(this); this.RedrawDirtyRectangleOnly = true; }
static protected void DrawBrick (Graphics graphics, Brush b1, Brush b2, Brush b3) { if (graphics == null) return; graphics.FillPolygon (b1, brickPoints1); graphics.FillPolygon (b2, brickPoints2); graphics.FillPolygon (b3, brickPoints3); }
public override void Paint(Graphics g) { if (g == null) throw new ArgumentNullException("The Graphics object is 'null'"); From.Paint(g); To.Paint(g); }
public override void DrawSelf(Graphics grfx) { grfx.Transform = this.TransformMatrix.GetMatrix(); grfx.FillRectangle(new SolidBrush(Color.FromArgb(Transparency, FillColor)), Rectangle); grfx.DrawRectangle(new Pen(LineColor, LineWidth), Rectangle.X, Rectangle.Y, Rectangle.Width, Rectangle.Height); grfx.Transform.Reset(); }
public CMain() { InitializeComponent(); Application.Idle += Application_Idle; MouseClick += CMain_MouseClick; MouseDown += CMain_MouseDown; MouseUp += CMain_MouseUp; MouseMove += CMain_MouseMove; MouseDoubleClick += CMain_MouseDoubleClick; KeyPress += CMain_KeyPress; KeyDown += CMain_KeyDown; KeyUp += CMain_KeyUp; Deactivate += CMain_Deactivate; MouseWheel += CMain_MouseWheel; SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.Selectable, true); FormBorderStyle = Settings.FullScreen ? FormBorderStyle.None : FormBorderStyle.FixedDialog; Graphics = CreateGraphics(); Graphics.SmoothingMode = SmoothingMode.AntiAlias; Graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; Graphics.CompositingQuality = CompositingQuality.HighQuality; Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; Graphics.TextContrast = 0; }
public override void DoPaint(Graphics g) { using (Brush b = new SolidBrush(ZenParams.WindowColor)) { g.FillRectangle(b, 0, 0, Width, Height); } }
public void Setup() { Bitmap bmp = new Bitmap(200, 100); m_graphics = Graphics.FromImage(bmp); m_gm = new GraphicsManager(null, m_graphics); }
public void PaintJunk(Graphics g) { g.FillRectangle(Brushes.Transparent, 0, 0, 1000, 1000); using (Font font = new Font("Courier New", 20, FontStyle.Bold)) { if (bounceCounter == -1) return; const string str = "DEVELOPER BUILD"; float x = 0; int timefactor = bounceCounter; for (int i = 0; i < str.Length; i++) { string slice = str.Substring(i, 1); g.PageUnit = GraphicsUnit.Pixel; x += g.MeasureString(slice, font).Width - 1; int offset = -i * 3 + timefactor*3; int yofs = 0; if (offset < 0) { continue; } else if (offset < DigitTable.Length) yofs = DigitTable[offset]; g.DrawString(slice, font, Brushes.Black, 5 + x, 15 - yofs); } } }
/// <summary> /// Initialize a new instance of the ViewContext class. /// </summary> /// <param name="control">Control associated with rendering.</param> /// <param name="alignControl">Control used for aligning elements.</param> /// <param name="graphics">Graphics instance for drawing.</param> /// <param name="renderer">Rendering provider.</param> public ViewContext(Control control, Control alignControl, Graphics graphics, IRenderer renderer) : this(null, control, alignControl, graphics, renderer) { }
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { var buttonRectangle = new Rectangle(cellBounds.X + 2, cellBounds.Y + 2, cellBounds.Width - 4, cellBounds.Height - 4); base.Paint(graphics, clipBounds, buttonRectangle, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); var imageRectangle = new Rectangle(cellBounds.X + 6, cellBounds.Y + 6, _detailImage.Width, _detailImage.Height); graphics.DrawImage(_detailImage, imageRectangle); }
public override void DrawAppointment(Graphics g, Rectangle rect, Appointment appointment, bool isSelected, Rectangle gripRect, bool enableShadows, bool useroundedCorners) { if (appointment == null) throw new ArgumentNullException("appointment"); if (g == null) throw new ArgumentNullException("g"); if (rect.Width != 0 && rect.Height != 0) using (StringFormat format = new StringFormat()) { format.Alignment = StringAlignment.Near; format.LineAlignment = StringAlignment.Near; if ((appointment.Locked) && isSelected) { // Draw back using (Brush m_Brush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.Wave, Color.LightGray, appointment.Color)) g.FillRectangle(m_Brush, rect); } else { // Draw back using (SolidBrush m_Brush = new SolidBrush(appointment.Color)) g.FillRectangle(m_Brush, rect); } if (isSelected) { using (Pen m_Pen = new Pen(appointment.BorderColor, 4)) g.DrawRectangle(m_Pen, rect); Rectangle m_BorderRectangle = rect; m_BorderRectangle.Inflate(2, 2); using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1)) g.DrawRectangle(m_Pen, m_BorderRectangle); m_BorderRectangle.Inflate(-4, -4); using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1)) g.DrawRectangle(m_Pen, m_BorderRectangle); } else { // Draw gripper gripRect.Width += 1; using (SolidBrush m_Brush = new SolidBrush(appointment.BorderColor)) g.FillRectangle(m_Brush, gripRect); using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1)) g.DrawRectangle(m_Pen, rect); } rect.X += gripRect.Width; g.DrawString(appointment.Subject, this.BaseFont, SystemBrushes.WindowText, rect, format); } }
public virtual Size GetCharacterSize( Graphics g, Font font, CharacterCasing casing ) { const int MeasureCharCount = 10; Size charSize = new Size( 0, 0 ); for ( char c = '0'; c <= '9'; ++c ) { Size newSize = TextRenderer.MeasureText( g, new string( c, MeasureCharCount ), font, new Size( 0, 0 ), _textFormatFlags ); newSize.Width = (int)Math.Ceiling( (double)newSize.Width / (double)MeasureCharCount ); if ( newSize.Width > charSize.Width ) { charSize.Width = newSize.Width; } if ( newSize.Height > charSize.Height ) { charSize.Height = newSize.Height; } } return charSize; }
// Methods public void Render(Graphics g, Character c) { int x, y; x = c.Location.X * m_blockSize; y = m_headerSize + c.Location.Y * m_blockSize; if (m_frame == 0) { RenderClosed(g, x, y); } else { if (c.Direction == Direction.Up) { RenderUp(g, x, y); } else if (c.Direction == Direction.Right) { RenderRight(g, x, y); } else if (c.Direction == Direction.Down) { RenderDown(g, x, y); } else { RenderLeft(g, x, y); } } m_frame = (m_frame + 1) % MaxFrames; }
private static SizeF CalcReciprocals(Graphics g) { switch(g.PageUnit) { case GraphicsUnit.World: case GraphicsUnit.Pixel: return new SizeF(1f,1f); case GraphicsUnit.Inch: return new SizeF(1f/g.DpiX,1f/g.DpiY); case GraphicsUnit.Millimeter: return new SizeF(25.4f/g.DpiX,25.4f/g.DpiY); case GraphicsUnit.Point: return new SizeF(72f/g.DpiX,72f/g.DpiY); case GraphicsUnit.Display: return new SizeF(75f/g.DpiX,75f/g.DpiY); case GraphicsUnit.Document: return new SizeF(300f/g.DpiX,300f/g.DpiY); } return new SizeF(10,10);//never gets here... }
public override SizeF Measure(Graphics graphics) { if (this.Image != null) { SizeF size = new Size(GraphConstants.MinimumItemWidth, GraphConstants.MinimumItemHeight); if (this.Width.HasValue) size.Width = Math.Max(size.Width, this.Width.Value); else size.Width = Math.Max(size.Width, this.Image.Width); if (this.Height.HasValue) size.Height = Math.Max(size.Height, this.Height.Value); else size.Height = Math.Max(size.Height, this.Image.Height); return size; } else { var size = new SizeF(GraphConstants.MinimumItemWidth, GraphConstants.MinimumItemHeight); if (this.Width.HasValue) size.Width = Math.Max(size.Width, this.Width.Value); if (this.Height.HasValue) size.Height = Math.Max(size.Height, this.Height.Value); return size; } }
/// <summary> /// Paints the wrapped IOGraph onto the specified viewport. Does nothing if no /// IOGraph has been provided. /// </summary> public void Paint(Graphics g, Rectangle viewportArea, float zoomFactor) { if(null != _graph) { _layoutManager.Layout(_graph, viewportArea.Size); _graphPainter.PaintNetwork(_graph, g, viewportArea, zoomFactor); } }
/// <summary></summary> /// <param name="box"></param> /// <param name="g"></param> protected override void PaintThisProgress(Rectangle box, Graphics g) { try { box.Width -= 1; box.Height -= 1; } catch {} if (box.Width <= 1) { return; } g.FillRectangle(brush, box); Rectangle innerBox = box; innerBox.Inflate(-1, -1); g.DrawRectangle(inner, innerBox); g.DrawLine(outer, box.X, box.Y, box.Right, box.Y); g.DrawLine(outer, box.X, box.Y, box.X, box.Bottom); g.DrawLine(edge, box.X, box.Bottom, box.Right, box.Bottom); if (gloss != null) { gloss.PaintGloss(box, g); } if (showEdge) { g.DrawLine(edge, box.Right, box.Y, box.Right, box.Bottom); } }
internal override void Draw(Graphics g) { IsInvalidated = false; Rectangle r = BaseElement.GetUnsignedRectangle(new Rectangle(location, size)); Point[] points = new Point[5]; points[0] = new Point(r.X + 0, r.Y + 0); points[1] = new Point(r.X + 0, r.Y + r.Height); points[2] = new Point(r.X + r.Width, r.Y + r.Height); //Fold points[3] = new Point(r.X + r.Width, r.Y + foldSize.Height); points[4] = new Point(r.X + r.Width - foldSize.Width, r.Y + 0); //foreach(Point p in points) p.Offset(location.X, location.Y); g.FillPolygon(GetBrush(r), points, FillMode.Alternate); g.DrawPolygon(new Pen(borderColor, borderWidth), points); g.DrawLine(new Pen(borderColor, borderWidth), new Point(r.X + r.Width - foldSize.Width, r.Y + foldSize.Height), new Point(r.X + r.Width, r.Y + foldSize.Height)); g.DrawLine(new Pen(borderColor, borderWidth), new Point(r.X + r.Width - foldSize.Width, r.Y + 0), new Point(r.X + r.Width - foldSize.Width, r.Y + 0 + foldSize.Height)); }
/// <summary> /// Constructor called that clears the field and also draws the board. /// </summary> /// <param name="g">The Graphics of the panel it draws on.</param> /// <param name="difficulty">The Difficulty of the Bot!</param> public Board(Graphics g, BotDifficulty difficulty) { _graphics = g; _botDifficulty = difficulty; ClearField(); DrawField(); }
public PaintScrollBarTrackEventArgs( Graphics graphics, Rectangle trackRect, Orientation orientation) : this(graphics, trackRect, orientation, true) { }
public Form1() { InitializeComponent(); g = pictureBox1.CreateGraphics(); }
/// <summary> /// 生成缩略图 /// </summary> /// <param name="originalImagePath">源图路径(物理路径)</param> /// <param name="thumbnailPath">缩略图路径(物理路径)</param> /// <param name="width">缩略图宽度</param> /// <param name="height">缩略图高度</param> /// <param name="mode">生成缩略图的方式</param> public static void MakeThumbnail(string originalImagePath, string thumbnailPath, int width, int height, string mode) { System.Drawing.Image originalImage = System.Drawing.Image.FromFile(originalImagePath); int towidth = width; int toheight = height; int x = 0; int y = 0; int ow = originalImage.Width; int oh = originalImage.Height; switch (mode) { case "HW": //指定高宽缩放(可能变形) break; case "W": //指定宽,高按比例 toheight = originalImage.Height * width / originalImage.Width; break; case "H": //指定高,宽按比例 towidth = originalImage.Width * height / originalImage.Height; break; case "Cut": //指定高宽裁减(不变形) if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight) { ow = originalImage.Width; oh = originalImage.Width * height / towidth; x = 0; y = (originalImage.Height - oh) / 2; } else { oh = originalImage.Height; ow = originalImage.Height * towidth / toheight; y = 0; x = (originalImage.Width - ow) / 2; } break; default: break; } //新建一个bmp图片 System.Drawing.Image bitmap = new System.Drawing.Bitmap(towidth, toheight); //新建一个画板 System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap); //设置高质量插值法 g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.CompositingQuality = CompositingQuality.HighQuality; //设置高质量,低速度呈现平滑程度 g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //清空画布并以透明背景色填充 g.Clear(Color.White); //在指定位置并且按指定大小绘制原图片的指定部分 g.DrawImage(originalImage, new System.Drawing.Rectangle(0, 0, towidth, toheight), new System.Drawing.Rectangle(x, y, ow, oh), System.Drawing.GraphicsUnit.Pixel); var encoderParams = new EncoderParameters(); long[] quality = new long[1]; quality[0] = 100; var encoderParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality); encoderParams.Param[0] = encoderParam; var lenEnd = originalImagePath.LastIndexOf('.'); var fileType = originalImagePath.Substring(lenEnd, originalImagePath.Length - lenEnd); ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders(); ImageCodecInfo jpegICI = null; ImageCodecInfo GIFICI = null; ImageCodecInfo jpgICI = null; ImageCodecInfo pngICI = null; ImageCodecInfo bmpICI = null; ImageCodecInfo allICI = null; foreach (var t in arrayICI) { if (t.FormatDescription.Equals("JPEG")) { jpegICI = t;//设置JPEG编码 } if (t.FormatDescription.Equals("GIF")) { GIFICI = t;//设置GIF编码 } if (t.FormatDescription.Equals("JPG")) { jpgICI = t;//设置GIF编码 } if (t.FormatDescription.Equals("PNG")) { pngICI = t;//设置GIF编码 } if (t.FormatDescription.Equals("BMP")) { bmpICI = t;//设置GIF编码 } } switch (fileType.ToLower()) { case ".jpg": allICI = jpegICI; break; case ".gif": allICI = GIFICI; break; case ".jpeg": allICI = jpegICI; break; case ".bmp": allICI = bmpICI; break; case ".png": allICI = pngICI; break; } try { bitmap.Save(thumbnailPath, allICI, encoderParams); ////以jpg格式保存缩略图 //bitmap.Save(thumbnailPath, System.Drawing.Imaging.ImageFormat.Jpeg); } catch (System.Exception e) { throw e; } finally { originalImage.Dispose(); bitmap.Dispose(); g.Dispose(); } }
private void RenderTab(System.Drawing.Graphics g, int index) { var rect = GetTabRect(index); var closeRect = GetCloseRect(index); var selected = SelectedIndex == index; var tab = TabPages[index]; var points = new[] { new Point(rect.Left, rect.Bottom), new Point(rect.Left, rect.Top + 3), new Point(rect.Left + 3, rect.Top), new Point(rect.Right - 3, rect.Top), new Point(rect.Right, rect.Top + 3), new Point(rect.Right, rect.Bottom), new Point(rect.Left, rect.Bottom) }; // Background var p = PointToClient(MousePosition); var hoverClose = closeRect.Contains(p); var hover = rect.Contains(p); var backColour = tab.BackColor; if (selected) { backColour = ControlPaint.Light(backColour, 1); } else if (hover) { backColour = ControlPaint.Light(backColour, 0.8f); } using (var b = new SolidBrush(backColour)) { g.FillPolygon(b, points); } // Border g.SmoothingMode = SmoothingMode.AntiAlias; g.DrawPolygon(SystemPens.ControlDark, points); if (selected) { using (var pen = new Pen(tab.BackColor)) { g.DrawLine(pen, rect.Left, rect.Bottom, rect.Right, rect.Bottom); } } // Text var textWidth = (int)g.MeasureString(tab.Text, Font).Width; var textLeft = rect.X + 14; var textRight = rect.Right - 26; var textRect = new Rectangle(textLeft + (textRight - textLeft - textWidth) / 2, rect.Y + 4, rect.Width - 26, rect.Height - 5); using (var b = new SolidBrush(tab.ForeColor)) { g.DrawString(tab.Text, Font, b, textRect); } // Close icon using (var pen = new Pen(tab.ForeColor)) { if (hoverClose) { g.DrawRectangle(pen, closeRect.Left + 1, closeRect.Top + 1, closeRect.Width - 2, closeRect.Height - 2); } const int padding = 5; g.DrawLine(pen, closeRect.Left + padding, closeRect.Top + padding, closeRect.Right - padding, closeRect.Bottom - padding); g.DrawLine(pen, closeRect.Right - padding, closeRect.Top + padding, closeRect.Left + padding, closeRect.Bottom - padding); } }
void DrawCaption(System.Drawing.Graphics g) { if (ClientRectangle.Width == 0 || ClientRectangle.Height == 0) { return; } if (DockPane.IsActivated) { var startColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveCaptionGradient.StartColor; var endColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveCaptionGradient.EndColor; var gradientMode = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveCaptionGradient.LinearGradientMode; using (var brush = new LinearGradientBrush(ClientRectangle, startColor, endColor, gradientMode)) { brush.Blend = ActiveBackColorGradientBlend; g.FillRectangle(brush, ClientRectangle); } } else { var startColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.InactiveCaptionGradient.StartColor; var endColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.InactiveCaptionGradient.EndColor; var gradientMode = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.InactiveCaptionGradient.LinearGradientMode; using (var brush = new LinearGradientBrush(ClientRectangle, startColor, endColor, gradientMode)) { g.FillRectangle(brush, ClientRectangle); } } var rectCaption = ClientRectangle; var rectCaptionText = rectCaption; rectCaptionText.X += TextGapLeft; rectCaptionText.Width -= TextGapLeft + TextGapRight; rectCaptionText.Width -= ButtonGapLeft + ButtonClose.Width + ButtonGapRight; if (ShouldShowAutoHideButton) { rectCaptionText.Width -= ButtonAutoHide.Width + ButtonGapBetween; } if (HasTabPageContextMenu) { rectCaptionText.Width -= ButtonOptions.Width + ButtonGapBetween; } rectCaptionText.Y += TextGapTop; rectCaptionText.Height -= TextGapTop + TextGapBottom; Color colorText; if (DockPane.IsActivated) { colorText = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveCaptionGradient.TextColor; } else { colorText = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.InactiveCaptionGradient.TextColor; } TextRenderer.DrawText(g, DockPane.CaptionText, TextFont, DrawHelper.RtlTransform(this, rectCaptionText), colorText, TextFormat); }
public void Draw(System.Drawing.Graphics graphics, Func <Vector3, Point> to2D, Action redraw, Perspective perspective) { //Do nothing }
/// <summary><![CDATA[ /// Resize an image on disk, constraining proportions /// (handles BMP, JPEG, GIF, TIFF, PNG); maintains /// transparency of PNG images. Filenames determine /// file types used automatically. /// ]]></summary> /// <example> /// <code><![CDATA[ /// Rectangle cropArea = new Rectangle(0, 0, 0, 0); /// string finalPath = ImagingHelpers.ResizeImage("/portfolio/picture01.jpg", 80, 320, 0, "/portfolio/temp/upload.jpg", cropArea); /// ]]></code> /// </example> /// <param name="imageSavePath">Web-style path with filename for the final resized image.</param> /// <param name="quality">Quality setting from 1 to 100 (for JPEG only; 0 for other types).</param> /// <param name="maxWidth">How wide to make the image, constraining the aspect ratio (0 ignore this param). /// Only one "Max" property can be used at a time - set the other to a zero.</param> /// <param name="maxHeight">How tall to make the image, constraining the aspect ratio (0 ignore this param).</param> /// <param name="path">Web-style path to the source image file.</param> /// <param name="cropArea">Rectangle object (left, top, width, height) to crop image. Leave out for no cropping.</param> /// <returns>The web path to the saved file on success, empty string on failure.</returns> public static string ResizeImage(string imageSavePath, int quality, int maxWidth, int maxHeight, string path, Rectangle cropArea) { maxWidth = System.Math.Abs(maxWidth); maxHeight = System.Math.Abs(maxHeight); if (maxWidth == 0 && maxHeight == 0) { return(string.Empty); } int intNewWidth = 0; int intNewHeight = 0; System.Drawing.Image image; if (imageSavePath.Length > 2) { if (imageSavePath.Substring(1, 1) != ":" && !imageSavePath.StartsWith(@"\\")) { imageSavePath = imageSavePath.MapPath(); } } string newPath = path; if (newPath.Length > 2) { if (newPath.Substring(1, 1) != ":" && !newPath.StartsWith(@"\\")) { newPath = newPath.MapPath(); } } try { if (cropArea.Top == 0 && cropArea.Bottom == 0 && cropArea.Width == 0 && cropArea.Height == 0) { image = System.Drawing.Image.FromFile(newPath); } else { image = CropImage(path, cropArea.Width, cropArea.Height, cropArea.Left, cropArea.Top); } int intOldWidth = image.Width; int intOldHeight = image.Height; if (maxWidth > 0) { if (intOldWidth != maxWidth) { //set new width and height double dblCoef = (double)maxWidth / (double)intOldWidth; intNewWidth = Convert.ToInt32(dblCoef * intOldWidth); intNewHeight = Convert.ToInt32(dblCoef * intOldHeight); } else { intNewWidth = intOldWidth; intNewHeight = intOldHeight; } } if (maxHeight > 0) { if (intOldHeight != maxHeight) { //set new width and height double dblCoef = (double)maxHeight / (double)intOldHeight; intNewWidth = Convert.ToInt32(dblCoef * intOldWidth); intNewHeight = Convert.ToInt32(dblCoef * intOldHeight); } else { intNewWidth = intOldWidth; intNewHeight = intOldHeight; } } System.Drawing.Image thumbnail = new Bitmap(intNewWidth, intNewHeight, PixelFormat.Format32bppPArgb); System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage(thumbnail); graphic.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; graphic.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; graphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; graphic.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; graphic.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; graphic.DrawImage(image, 0, 0, thumbnail.Width, thumbnail.Height); ImageCodecInfo[] info = ImageCodecInfo.GetImageEncoders(); int encoder = 1; switch (imageSavePath.Right(4).ToLower()) { case ".bmp": encoder = 0; break; case ".jpg": encoder = 1; break; case ".gif": encoder = 2; break; case ".tif": encoder = 3; break; case ".png": encoder = 4; break; } switch (imageSavePath.Right(5).ToLower()) { case ".jpeg": encoder = 1; break; case ".tiff": encoder = 3; break; } if (encoder != 1) { quality = 100; } EncoderParameters encoderParameters; encoderParameters = new EncoderParameters(1); encoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)quality); thumbnail.Save(imageSavePath, info[encoder], encoderParameters); image.Dispose(); thumbnail.Dispose(); graphic.Dispose(); encoderParameters.Dispose(); return(imageSavePath); } catch (Exception e) { return(e.ToString()); } }
protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { DataGridViewProgressCellPaintStateEventArgs arg = formattedValue as DataGridViewProgressCellPaintStateEventArgs; bool selected = ((cellState & DataGridViewElementStates.Selected) == DataGridViewElementStates.Selected); arg.CellState = cellState; if (selected) { if (arg.Value >= 0 && arg.Value <= 100) { arg.ForeColorProgress = cellStyle.SelectionForeColor; arg.BackColorProgress = ProgressBarColorSelection; } else if (arg.BackColorProgress == ProgressBarColorDefault) { arg.ForeColorProgress = cellStyle.SelectionForeColor; arg.BackColorProgress = ProgressBarColorSelection; } } OnPaintCellState(arg); Rectangle rcProgress = new Rectangle( cellBounds.X + 2, cellBounds.Y + 2, Convert.ToInt32((1.0f * cellBounds.Width * 0.95)), cellBounds.Height - 5); //evaluating text position according to alignment PointF ptText = DrawTextPlace(arg.Text, cellStyle, cellStyle.Alignment, cellBounds); ptText.X -= rcProgress.X; ptText.Y -= rcProgress.Y; Bitmap bmpDefault = new Bitmap(rcProgress.Width, rcProgress.Height); Bitmap bmpProgress = new Bitmap(rcProgress.Width, rcProgress.Height); DrawCellShadow(rcProgress, cellStyle, arg, ptText, bmpDefault, false); DrawCellShadow(rcProgress, cellStyle, arg, ptText, bmpProgress, true); //Combine images if (arg.Percent > 0) { float w = arg.Percent * rcProgress.Width; using (Graphics gr = Graphics.FromImage(bmpDefault)) { RectangleF rcf = new RectangleF(0, 0, w, rcProgress.Height); gr.DrawImage(bmpProgress, rcf, rcf, GraphicsUnit.Pixel); } } ptText.X += rcProgress.X; ptText.Y += rcProgress.Y; //Fill all area SolidBrush brBack = new SolidBrush( selected ? cellStyle.SelectionBackColor : cellStyle.BackColor ); g.FillRectangle(brBack, cellBounds); brBack.Dispose(); //Draw Grid Pen gridColorPen = new Pen(this.DataGridView.GridColor, 0.5F); int xw = cellBounds.X + cellBounds.Width; int yh = cellBounds.Y + cellBounds.Height; if (this.ColumnIndex != this.DataGridView.ColumnCount - 1) { xw--; } if (this.RowIndex != this.DataGridView.RowCount - 1) { yh--; } //g.DrawLine(gridColorPen, cellBounds.X, cellBounds.Y, xw, cellBounds.Y); //Top if (this.ColumnIndex == 0) { g.DrawLine(gridColorPen, cellBounds.X, cellBounds.Y, cellBounds.X, yh); //Left } g.DrawLine(gridColorPen, xw, cellBounds.Y, xw, yh - 1); //Right g.DrawLine(gridColorPen, cellBounds.X, yh - 1, xw, yh - 1); //Bottom gridColorPen.Dispose(); g.DrawImage(bmpDefault, rcProgress.Location); }
public void DrawHorizontal(System.Drawing.Graphics g, LiveSplitState state, float height, Region clipRegion) { InternalComponent.DrawHorizontal(g, state, height, clipRegion); }
protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush, bool alignToRight) { object o = this.GetColumnValueAtRow(source, rowNum); if (o != null) { int i = (int)o; g.FillRectangle(backBrush, bounds); Bitmap bmp = (Bitmap)theImages[i]; GridImageCellDrawOption cellDrawOption = GridImageCellDrawOption.NoResize; //GridImageCellDrawOption cellDrawOption = GridImageCellDrawOption.FitProportionally; //GridImageCellDrawOption cellDrawOption = GridImageCellDrawOption.FitToCell; System.Drawing.GraphicsUnit gu = System.Drawing.GraphicsUnit.Point; RectangleF srcRect = bmp.GetBounds(ref gu); Rectangle destRect = Rectangle.Empty; Region saveRegion = g.Clip; int DrawX = bounds.X + (bounds.Width - (int)srcRect.Width) / 2; int DrawY = bounds.Y + (bounds.Height - (int)srcRect.Height) / 2; destRect = new Rectangle(DrawX, DrawY, (int)srcRect.Width, (int)srcRect.Height); g.Clip = new Region(bounds); // switch(cellDrawOption) // { // case GridImageCellDrawOption.FitToCell: // destRect = bounds; // break; // case GridImageCellDrawOption.NoResize: // destRect = new Rectangle(bounds.X, bounds.Y, (int) srcRect.Width, (int) srcRect.Height); // g.Clip = new Region(bounds); // break; // case GridImageCellDrawOption.FitProportionally: // { // float srcRatio = srcRect.Width / srcRect.Height; // float tarRatio = (float) bounds.Width / bounds.Height; // destRect = bounds; // if( tarRatio < srcRatio ) // { // destRect.Height = (int) (destRect.Width * srcRatio); // } // else // { // destRect.Width = (int) (destRect.Height * srcRatio); // } // } // break; // // default: // break; // } if (!destRect.IsEmpty) { g.DrawImage(bmp, destRect, srcRect, gu); } g.Clip = saveRegion; } }
private void DrawPoint(System.Drawing.Graphics gfx, System.Drawing.Pen pen, Point2D pt) { gfx.DrawEllipse(pen, pt.P().X - 2.0f, pt.P().Y - 2.0f, 4.0f, 4.0f); }
public void DrawVertical(System.Drawing.Graphics g, LiveSplitState state, float width, Region clipRegion) { InternalComponent.DrawVertical(g, state, width, clipRegion); }
private void DrawScreen(System.Drawing.Graphics gfx) { // to prevent unecessary drawing if (pts_.Count == 0) { return; } // pens used for drawing elements of the display System.Drawing.Pen polyPen = new Pen(Color.Blue, 1.0f); System.Drawing.Pen shellPen = new Pen(Color.Red, 0.5f); System.Drawing.Pen splinePen = new Pen(Color.Black, 1.5f); if (Menu_Shell.Checked && Menu_Shell.Enabled) { // draw the shell DrawShell(gfx, shellPen, pts_, tVal_); } if (Menu_Polyline.Checked && Menu_Polyline.Enabled) { DrawPolyline(gfx, polyPen, pts_); } if (Menu_Points.Checked && Menu_Points.Enabled) { DrawPoints(gfx, polyPen, pts_); } if (assignment_ == 0) { return; } /////////////////////////////////////////////////////////////////////////////// // Drawing code for algorithms goes in here // /////////////////////////////////////////////////////////////////////////////// // you can change these variables at will; i have just chosen there // to be six sample points for every point placed on the screen float steps = pts_.Count * 6; float alpha = 1 / steps; //HUD drawing code Font arial = new Font("Arial", 15); int widthoffset, heightoffset; //bool somethingselected = true; //String DrawLabel; widthoffset = 10; heightoffset = 30; gfx.DrawString("Assignment " + assignment_.ToString() + ": " + method_.ToString(), arial, Brushes.Black, widthoffset, heightoffset); heightoffset += arial.Height; /* * if (assignment_ == 1) * { * //Draws the mouse projected onto our curve * gfx.DrawString("Mouse(" + ProjectedMouse_.x.ToString() + ", " + ProjectedMouse_.y.ToString() + ") ", arial, Brushes.Black, widthoffset, heightoffset); * gfx.DrawEllipse(splinePen, ProjectedMouse_.P().X - 2.0f, ProjectedMouse_.P().Y - 2.0f, 4.0f, 4.0f); * heightoffset += arial.Height; * } */ if (assignment_ == 1 || assignment_ == 7) { gfx.DrawString("Coefficients :" + pts_.Count.ToString(), arial, Brushes.Black, widthoffset, heightoffset); widthoffset += 150; } else { gfx.DrawString("points: " + pts_.Count.ToString(), arial, Brushes.Black, widthoffset, heightoffset); widthoffset += 100; } if (pts_.Count > 0) { gfx.DrawString("t-value: " + tVal_.ToString("F"), arial, Brushes.Black, widthoffset, heightoffset); widthoffset += 150; gfx.DrawString("t-step: " + alpha.ToString("F6"), arial, Brushes.Black, widthoffset, heightoffset); } widthoffset = 10; heightoffset += arial.Height; if (assignment_ == 1 || assignment_ == 7) { for (int i = 0; i < pts_.Count; ++i) { gfx.DrawString("A" + i.ToString() + ": " + pts_[i].y.ToString(), arial, Brushes.Black, widthoffset, heightoffset + i * arial.Height); } } else { for (int i = 0; i < pts_.Count; ++i) { gfx.DrawString("points" + i.ToString() + ": " + pts_[i].ToString(), arial, Brushes.Black, widthoffset, heightoffset + i * arial.Height); } } /////////////////////////////////////////////////////////////////////////////// // Draw Axes for Assignment 11 // /////////////////////////////////////////////////////////////////////////////// if (assignment_ == 1 || assignment_ == 7) { //Draw Axes Point2D Origin = new Point2D(0.0f, 0.0f); Point2D XPos = new Point2D(1.0f, 0.0f); Point2D YPos = new Point2D(0.0f, 4.0f); Point2D YNeg = new Point2D(0.0f, -4.0f); gfx.DrawLine(polyPen, YNeg.P(), YPos.P()); gfx.DrawLine(polyPen, Origin.P(), XPos.P()); Point2D Tick1 = new Point2D(YPos); Point2D Tick2 = new Point2D(YPos); Tick1.x = -0.01f * (XPos.x - Origin.x); Tick2.x = 0.01f * (XPos.x - Origin.x); //Draw Tick Marks while (Tick1.y > YNeg.y) { Tick2.y = Tick1.y; gfx.DrawLine(polyPen, Tick1.P(), Tick2.P()); Tick1.y -= 1.0f; } Tick1.x = Tick2.x = XPos.x; Tick1.y = -0.01f * (YPos.y - YNeg.y); Tick2.y = 0.01f * (YPos.y - YNeg.y); gfx.DrawLine(polyPen, Tick1.P(), Tick2.P()); } if (pts_.Count < 2) { return; } Point2D current_left, current_right; switch (method_) { case Method.DeCastlejau: current_right = DeCastlejau(0); for (float t = alpha; t < 1; t += alpha) { current_left = current_right; current_right = DeCastlejau(t); gfx.DrawLine(splinePen, current_left.P(), current_right.P()); } current_left = current_right; current_right = DeCastlejau(1); gfx.DrawLine(splinePen, current_left.P(), current_right.P()); break; case Method.Bernstein: current_right = Bernstein(0); for (float t = alpha; t < 1; t += alpha) { current_left = current_right; current_right = Bernstein(t); gfx.DrawLine(splinePen, current_left.P(), current_right.P()); } current_left = current_right; current_right = Bernstein(1); gfx.DrawLine(splinePen, current_left.P(), current_right.P()); break; case Method.MidpointSubdivision: List <Point2D> points = GetMidpointSubdivision(iterations_, pts_); for (int i = 0; i + 1 < points.Count; ++i) { gfx.DrawLine(splinePen, points[i].P(), points[i + 1].P()); } //DrawMidpoint(gfx, splinePen, pts_, iterations_); break; case Method.Inter_Poly: current_right = PolyInterpolate(0); for (float t = alpha; t < 1; t += alpha) { current_left = current_right; current_right = PolyInterpolate(t); gfx.DrawLine(splinePen, current_left.P(), current_right.P()); } current_left = current_right; current_right = PolyInterpolate(1); gfx.DrawLine(splinePen, current_left.P(), current_right.P()); break; case Method.Inter_Spline: // spline interpolation CubicSplineLinearSystem(); current_right = new Point2D(SplineInterpolate(0)); for (float t = alpha; t < pts_.Count - 1; t += alpha) { current_left = current_right; current_right = SplineInterpolate(t); gfx.DrawLine(splinePen, current_left.P(), current_right.P()); } break; case Method.DeBoor: if (pts_.Count >= 2) { current_right = new Point2D(DeBoorAlgthm(knot_[degree_])); float lastT = knot_[knot_.Count - degree_ - 1] - alpha; for (float t = alpha; t < lastT; t += alpha) { current_left = current_right; current_right = DeBoorAlgthm(t); gfx.DrawLine(splinePen, current_left.P(), current_right.P()); } gfx.DrawLine(splinePen, current_right.P(), DeBoorAlgthm(lastT).P()); } break; } /////////////////////////////////////////////////////////////////////////////// // Drawing code end // /////////////////////////////////////////////////////////////////////////////// }
/// <summary> /// 生成缩略图 /// </summary> /// <param name="originalImagePath">源图路径(物理路径)</param> /// <param name="thumbnailPath">缩略图路径(物理路径)</param> /// <param name="width">缩略图宽度</param> /// <param name="height">缩略图高度</param> /// <param name="mode">生成缩略图的方式</param> public static void MakeThumbnail(string originalImagePath, string thumbnailPath, int width, int height, string mode) { System.Drawing.Image originalImage = System.Drawing.Image.FromFile(originalImagePath); int towidth = width; int toheight = height; int x = 0; int y = 0; int ow = originalImage.Width; int oh = originalImage.Height; switch (mode) { case "HW": //指定高宽缩放(可能变形) break; case "W": //指定宽,高按比例 toheight = originalImage.Height * width / originalImage.Width; break; case "H": //指定高,宽按比例 towidth = originalImage.Width * height / originalImage.Height; break; case "Cut": //指定高宽裁减(不变形) if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight) { oh = originalImage.Height; ow = originalImage.Height * towidth / toheight; y = 0; x = (originalImage.Width - ow) / 2; } else { ow = originalImage.Width; oh = originalImage.Width * height / towidth; x = 0; y = (originalImage.Height - oh) / 2; } break; default: break; } //新建一个bmp图片 System.Drawing.Image bitmap = new System.Drawing.Bitmap(towidth, toheight); //新建一个画板 System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap); //设置高质量插值法 g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; //设置高质量,低速度呈现平滑程度 g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //清空画布并以透明背景色填充 g.Clear(System.Drawing.Color.Transparent); //在指定位置并且按指定大小绘制原图片的指定部分 g.DrawImage(originalImage, new System.Drawing.Rectangle(0, 0, towidth, toheight), new System.Drawing.Rectangle(x, y, ow, oh), System.Drawing.GraphicsUnit.Pixel); try { //以jpg格式保存缩略图 bitmap.Save(thumbnailPath, System.Drawing.Imaging.ImageFormat.Jpeg); } catch (System.Exception e) { throw e; } finally { originalImage.Dispose(); bitmap.Dispose(); g.Dispose(); } }
public static System.Drawing.Graphics smethod_0(Image image) { System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(image); graphics.TextRenderingHint = TextRenderingHint.AntiAlias; return(graphics); }
/// <summary> /// 获得操作系统消息 /// </summary> /// <param name="m"></param> protected override void WndProc(ref Message m) { base.WndProc(ref m); if (m.Msg == 0xf || m.Msg == 0x133) { #region 注释 //拦截系统消息,获得当前控件进程以便重绘。 //一些控件(如TextBox、Button等)是由系统进程绘制,重载OnPaint方法将不起作用. //所有这里并没有使用重载OnPaint方法绘制TextBox边框。 // //MSDN:重写 OnPaint 将禁止修改所有控件的外观。 //那些由 Windows 完成其所有绘图的控件(例如 Textbox)从不调用它们的 OnPaint 方法, //因此将永远不会使用自定义代码。请参见您要修改的特定控件的文档, //查看 OnPaint 方法是否可用。如果某个控件未将 OnPaint 作为成员方法列出, //则您无法通过重写此方法改变其外观。 // //MSDN:要了解可用的 Message.Msg、Message.LParam 和 Message.WParam 值, //请参考位于 MSDN Library 中的 Platform SDK 文档参考。可在 Platform SDK(“Core SDK”一节) //下载中包含的 windows.h 头文件中找到实际常数值,该文件也可在 MSDN 上找到。 #endregion IntPtr hDC = GetWindowDC(m.HWnd); if (hDC.ToInt32() == 0) { return; } System.Drawing.Graphics g = Graphics.FromHdc(hDC); #region 画边框 if (this.BorderStyle != BorderStyle.None) { //边框Width为1个像素 System.Drawing.Pen pen = new Pen(ControlFaceSchema.BorderNormalStyle.Color1, 1); if (this.Enabled) { if (ControlState == ControlState.Hover) { pen.Color = ControlFaceSchema.BorderHoverStyle.Color1; } else { if (this.Focused) { pen.Color = ControlFaceSchema.BorderHoverStyle.Color1; } else { pen.Color = ControlFaceSchema.BorderNormalStyle.Color1; } } } else { pen.Color = ControlFaceSchema.BorderDisabledStyle.Color1; } //绘制边框 g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.DrawRectangle(pen, 0, 0, this.Width - 1, this.Height - 1); pen.Dispose(); } #endregion #region 画水印提示 if (Text.Length == 0 && !string.IsNullOrEmpty(_emptyTextTip) && !Focused && Enabled) { TextFormatFlags format = TextFormatFlags.EndEllipsis | TextFormatFlags.VerticalCenter; if (RightToLeft == RightToLeft.Yes) { format |= TextFormatFlags.RightToLeft | TextFormatFlags.Right; } TextRenderer.DrawText( g, _emptyTextTip, Font, base.ClientRectangle, _emptyTextTipColor, format); } #endregion //返回结果 m.Result = IntPtr.Zero; //释放 ReleaseDC(m.HWnd, hDC); g.Dispose(); } }
/// <summary> /// Renders the chart /// </summary> /// <param name="graphics">Graphics object to output the drawing</param> /// <param name="width">Specifies the Width of the chart</param> /// <param name="height">Specifies the height of the chart</param> public override void Render(System.Drawing.Graphics graphics, int width, int height) { ChartEngine engine = this.Engine; float scaleX = engine.ScaleX, scaleY = engine.ScaleY; Pen pen = this.Line.GetPen(graphics); Brush brush = this.Fill.GetBrush(graphics); float xStart = 0, xWidth; int xCount = 0, xPosFinal = 0; if (engine.Charts.Count > 1) { foreach (Chart c in engine.Charts) { if (c.Equals(this)) { xPosFinal = xCount; } if (c as MapColumnChart != null) { xCount++; } } xWidth = ((scaleX - 1) / xCount); xStart = xWidth * xPosFinal + 1; } else { xStart = 1; xWidth = scaleX; } float y; float yHeight; float x = 0; foreach (ChartPoint p in this.Data) { if (p.YValue * scaleY < 0) { y = (p.YValue * scaleY); yHeight = -(p.YValue * scaleY); } else { y = 0; yHeight = (p.YValue * scaleY); } Rectangle rect = new Rectangle( (int)((float)(x * scaleX) + xStart), (int)y, (int)xWidth, (int)yHeight); Point [] points = new Point[] { rect.Location }; graphics.TransformPoints( System.Drawing.Drawing2D.CoordinateSpace.Page, System.Drawing.Drawing2D.CoordinateSpace.World, points); if (this.rects != null) { this.rects.Add( new Rectangle( points[0], new Size((int)xWidth, (int)yHeight)) ); } graphics.FillRectangle(brush, rect); graphics.DrawRectangle(pen, rect); x++; } }
public void Draw(System.Drawing.Graphics graphics) { graphics.DrawPolygon(new Pen(Color.Brown), ReceiverCoord); }
public static Bitmap DrawToBitmap(IPresentationImage image, ExportImageParams exportParams) { Platform.CheckForNullReference(image, "image"); Platform.CheckForNullReference(exportParams, "exportParams"); if (!(image is ISpatialTransformProvider) || !(image is IImageGraphicProvider)) { throw new ArgumentException("The image must implement IImageGraphicProvider and have a valid ImageSpatialTransform in order to be exported."); } if (exportParams.ExportOption == ExportOption.TrueSize) { var imageSopProvider = image as IImageSopProvider; var pixelSpacing = imageSopProvider == null ? null : imageSopProvider.Frame.NormalizedPixelSpacing; if (pixelSpacing == null || pixelSpacing.IsNull) { throw new ArgumentException("The image does not contain pixel spacing information. TrueSize export is not possible."); } } ImageSpatialTransform transform = ((ISpatialTransformProvider)image).SpatialTransform as ImageSpatialTransform; if (transform == null) { throw new ArgumentException("The image must have a valid ImageSpatialTransform in order to be exported."); } if (exportParams.ExportOption == ExportOption.TrueSize) { return(DrawTrueSizeImageToBitmap(image, exportParams.OutputSize, exportParams.Dpi)); } if (exportParams.SizeMode == SizeMode.Scale) { // TODO: Refactor ImageExporter, so there only the displayRectangle and OutputRectangle are provided // Scale can be automatically figured out. // A "Padded" option can be provided to distinguish between the current Fixed and ScaleToFit options // TODO: Refactor ImageExporter, so there are separate exporters for each ExportOption. // The ExportImageParams is getting too many options and not all of them are applicable to each exporter // Instead, each exporter should have its own parameters. if (exportParams.ExportOption == ExportOption.Wysiwyg) { return(DrawWysiwygImageToBitmap(image, exportParams.DisplayRectangle, exportParams.Scale, exportParams.Dpi)); } else { return(DrawCompleteImageToBitmap(image, exportParams.Scale, exportParams.Dpi)); } } else if (exportParams.SizeMode == SizeMode.ScaleToFit) { if (exportParams.ExportOption == ExportOption.Wysiwyg) { var scale = ScaleToFit(exportParams.DisplayRectangle.Size, exportParams.OutputSize); return(DrawWysiwygImageToBitmap(image, exportParams.DisplayRectangle, scale, exportParams.Dpi)); } else { var sourceImage = (IImageGraphicProvider)image; var scale = ScaleToFit(new Size(sourceImage.ImageGraphic.Columns, sourceImage.ImageGraphic.Rows), exportParams.OutputSize); return(DrawCompleteImageToBitmap(image, scale, exportParams.Dpi)); } } else { Bitmap paddedImage = new Bitmap(exportParams.OutputSize.Width, exportParams.OutputSize.Height); using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(paddedImage)) { // paint background using (Brush b = new SolidBrush(exportParams.BackgroundColor)) { graphics.FillRectangle(b, new Rectangle(Point.Empty, exportParams.OutputSize)); } // paint image portion Bitmap bmp; if (exportParams.ExportOption == ExportOption.Wysiwyg) { float scale = ScaleToFit(exportParams.DisplayRectangle.Size, exportParams.OutputSize); bmp = DrawWysiwygImageToBitmap(image, exportParams.DisplayRectangle, scale, exportParams.Dpi); } else { IImageGraphicProvider sourceImage = (IImageGraphicProvider)image; float scale = ScaleToFit(new Size(sourceImage.ImageGraphic.Columns, sourceImage.ImageGraphic.Rows), exportParams.OutputSize); bmp = DrawCompleteImageToBitmap(image, scale, exportParams.Dpi); } graphics.DrawImageUnscaledAndClipped(bmp, new Rectangle(CenterRectangles(bmp.Size, exportParams.OutputSize), bmp.Size)); bmp.Dispose(); } return(paddedImage); } }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Accepts a string and figures out what area is required to display it. /// It then takes looks at the form factor of an existing label and increases /// the form dimensions so that the label becomes that size. It takes care to /// preserve the height to width ratio of the original form /// </summary> /// <remarks>The text box must be anchored so the increase in form size will cause an increase /// in width</remarks> /// <param name="strIn">Incoming string to measure</param> /// <param name="labelIn">label which should be increased</param> protected void AdjustFormToTextDimensions(string strIn, System.Windows.Forms.Label labelIn) { int textArea; int originalArea; int newHeight; int newWidth; int heightDifference; int widthDifference; if (labelIn == null) { return; } if (strIn == null) { return; } if (strIn.Length == 0) { return; } System.Drawing.Graphics gr = this.CreateGraphics(); SizeF sF = gr.MeasureString(strIn, labelIn.Font); // now we have the height and width calculate the total area // in square pixels textArea = (int)sF.Height * (int)sF.Width; if (textArea <= 0) { return; } // now calculate the original area of the text box originalArea = labelIn.Height * labelIn.Width; // if the new area is smaller than the old we do not need to do anything // we never shink the box if (originalArea >= textArea) { return; } // get the new height and width - which is in the same ratio as the // original (this works - you do the math!!!) newHeight = (int)Math.Sqrt((textArea * labelIn.Height) / labelIn.Width); newWidth = (int)Math.Sqrt((textArea * labelIn.Width) / labelIn.Height); // now get the difference between the new height and the old height heightDifference = newHeight - labelIn.Height; widthDifference = newWidth - labelIn.Width; // some sanity checks if (heightDifference <= 0) { return; } if (widthDifference <= 0) { return; } // increase the form size (not the text box size) by the differences. The // text box should be anchored so the increase in form size will cause an increase // in width this.Height += heightDifference; this.Width += widthDifference; // some sanity checks if (this.Height >= 640) { this.Height = 640; } if (this.Width >= 480) { this.Width = 480; } }
public static IntPtr GetNativeGraphics(System.Drawing.Graphics graphics) { return(internals.GetNativeGraphics(graphics)); }
internal void Draw(System.Drawing.Graphics g) { g.FillRectangle(Brushes.Violet, Coordinates); }
protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, swf.DataGridViewPaintParts paintParts) { Handler.Paint(graphics, clipBounds, ref cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, ref paintParts); base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); }
private void CreateThumbnail(System.Drawing.Image original_image, ref System.Drawing.Bitmap final_image, ref System.Drawing.Graphics graphic, ref MemoryStream ms, HttpPostedFile jpeg_image_upload, int width, int height, int target_width, int target_height, string prefix, bool thumb, bool watermark, out int new_width, out int new_height, string fileName) // , out string thumbnail_id { int indexOfExtension = System.IO.Path.GetFileName(jpeg_image_upload.FileName).LastIndexOf("."); string imageFileName = System.IO.Path.GetFileName(jpeg_image_upload.FileName).Substring(0, indexOfExtension); float image_ratio = (float)width / (float)height; if (width > height) { if (image_ratio > 1.5) { // If Image width is lot greater than height, then do following if (width > 100 && width < 200) { target_width = width; } else if (width > 200) { target_width = 200; } } } float target_ratio = (float)target_width / (float)target_height; if (target_ratio > image_ratio) { new_height = target_height; new_width = (int)Math.Floor(image_ratio * (float)target_height); } else { new_height = (int)Math.Floor((float)target_width / image_ratio); new_width = target_width; } new_width = new_width > target_width ? target_width : new_width; new_height = new_height > target_height ? target_height : new_height; //final_image = new System.Drawing.Bitmap(target_width, target_height); final_image = new System.Drawing.Bitmap(new_width, new_height); graphic = System.Drawing.Graphics.FromImage(final_image); graphic.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Transparent), new System.Drawing.Rectangle(0, 0, new_width, new_height)); //int paste_x = (target_width - new_width) / 2; //int paste_y = (target_height - new_height) / 2; graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; /* new way */ //graphic.DrawImage(original_image, paste_x, paste_y, new_width, new_height); graphic.DrawImage(original_image, 0, 0, new_width, new_height); ms = new MemoryStream(); final_image.Save(ms, System.Drawing.Imaging.ImageFormat.Png); saveJpeg(UploadImagePath + fileName, final_image, 100); //jpeg_image_upload.FileName ms.Dispose(); }
internal static void DrawImage(System.Drawing.Graphics graphics, Image image, RectangleF rectDestMM, RectangleF rectSourcePX) { DrawImage(graphics, image, rectDestMM, rectSourcePX, null); }
public void Draw(System.Drawing.Graphics graphics) { graphics.DrawPolygon(new Pen(Color.DarkRed), ArrayVertices); }
public void draw(System.Drawing.Graphics g) { g.DrawImage(isles1, x, y, isles1.Width, isles1.Height); }
///// <param name="thumbnailPath">缩略图路径(物理路径)</param> /// <summary> /// 生成缩略图 /// </summary> /// <param name="originalImageStream">源图字节</param> /// <param name="width">缩略图宽度</param> /// <param name="height">缩略图高度</param> /// <param name="model">图片缩量方式</param> /// <param name="imgFomat">图片类型</param> public static byte[] MakeThumbnail(Stream originalImageStream, int width, int height, ImgModel model, ImageFormat imgFomat) { System.Drawing.Image originalImage = System.Drawing.Image.FromStream(originalImageStream); int towidth = width; int toheight = height; int x = 0; int y = 0; int ow = originalImage.Width; int oh = originalImage.Height; switch (model) { case ImgModel.Hw: //指定高宽缩放(可能变形) break; case ImgModel.W: //指定宽,高按比例 toheight = originalImage.Height * width / originalImage.Width; break; case ImgModel.H: //指定高,宽按比例 towidth = originalImage.Width * height / originalImage.Height; break; case ImgModel.Cut: //指定高宽裁减(不变形) oh = originalImage.Height; ow = originalImage.Width; x = 0; y = 0; //if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight) //{ // oh = originalImage.Height; // ow = originalImage.Height * towidth / toheight; // y = 0; // x = (originalImage.Width - ow) / 2; //} //else //{ // ow = originalImage.Width; // oh = originalImage.Width * height / towidth; // x = 0; // y = (originalImage.Height - oh); //} break; default: break; } //新建一个bmp图片 System.Drawing.Image bitmap = new System.Drawing.Bitmap(towidth, toheight); //新建一个画板 System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap); //设置高质量插值法 g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; //设置高质量,低速度呈现平滑程度 g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //清空画布并以透明背景色填充 g.Clear(System.Drawing.Color.Transparent); //在指定位置并且按指定大小绘制原图片的指定部分 g.DrawImage(originalImage, new System.Drawing.Rectangle(0, 0, towidth, toheight), new System.Drawing.Rectangle(x, y, ow, oh), System.Drawing.GraphicsUnit.Pixel); try { //以指定格式保存缩略图 return(ImageToByteArray(bitmap, imgFomat)); } finally { originalImage.Dispose(); bitmap.Dispose(); g.Dispose(); } }
Bitmap GetBitmap(State state) { int topBorderSize = 14; var worldInfo = state.worldInfo; var worldZones = state.worldZones; var poiZones = state.poiZones; var playerZones = state.playerZones; var active = state.active; var inactive = state.inactive; if (worldInfo.w == 0 || worldInfo.h == 0) { return(null); } Bitmap bm = new Bitmap(ScaleCoord(worldInfo.w), ScaleCoord(worldInfo.h) + topBorderSize); using (System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bm)) { gr.SmoothingMode = SmoothingMode.None; gr.Clear(System.Drawing.Color.Black); // World Zones if (chkGrid.Checked && worldZones.zones != null) { foreach (var zone in worldZones.zones) { gr.DrawRectangle(Pens.Gray, ScaleCoord(zone.x1), ScaleCoord(zone.y1), ScaleCoord(zone.x2 - zone.x1), ScaleCoord(zone.y2 - zone.y1)); } } // POIS if (chkPOIs.Checked && poiZones.zones != null) { foreach (var poi in poiZones.zones) { // Zone gr.DrawRectangle(Pens.DarkGray, ScaleCoord(poi.x1), ScaleCoord(poi.y1), ScaleCoord(poi.x2 - poi.x1), ScaleCoord(poi.y2 - poi.y1)); } } // Draw inactive. if (chkInactive.Checked && inactive.list != null) { foreach (var zombie in inactive.list) { gr.FillEllipse(Brushes.Red, ScaleCoord(zombie.x), ScaleCoord(zombie.y), 2, 2); } } // Active if (chkActive.Checked && active.list != null) { foreach (var zombie in active.list) { gr.FillEllipse(Brushes.Blue, ScaleCoord(zombie.x), ScaleCoord(zombie.y), 2, 2); } } // Visible zones. if (chkPlayers.Checked && playerZones.zones != null) { foreach (var zone in playerZones.zones) { // Zone gr.DrawRectangle(Pens.Green, ScaleCoord(zone.x1), ScaleCoord(zone.y1), ScaleCoord(zone.x2 - zone.x1), ScaleCoord(zone.y2 - zone.y1)); // Spawn Block. gr.DrawRectangle(Pens.Yellow, ScaleCoord(zone.x3), ScaleCoord(zone.y3), ScaleCoord(zone.x4 - zone.x3), ScaleCoord(zone.y4 - zone.y3)); } } // Sounds { var sounds = state.sounds; if (sounds != null) { foreach (var snd in sounds) { var elapsed = snd.watch.ElapsedMilliseconds; var alpha = (elapsed / 1000.0f); int dim = (int)(alpha * snd.radius) * 2; int x = snd.x - (dim / 2); int y = snd.y - (dim / 2); gr.DrawEllipse(Pens.Green, ScaleCoord(x), ScaleCoord(y), ScaleCoord(dim), ScaleCoord(dim)); } } } // Stats { gr.FillRectangle(Brushes.Black, 0, 0, worldInfo.mapW, 20); float x = 4.0f; gr.DrawString(string.Format("Speed: {0}x", worldInfo.timescale), SystemFonts.DefaultFont, Brushes.Green, x, 4.0f); x += 70.0f; gr.DrawString(string.Format("Map: {0}x{1}", worldInfo.mapW, worldInfo.mapH), SystemFonts.DefaultFont, Brushes.Green, x, 4.0f); x += 100.0f; gr.DrawString(string.Format("Density: {0}/km²", worldInfo.density), SystemFonts.DefaultFont, Brushes.Green, x, 4.0f); x += 100.0f; gr.DrawString(string.Format("Inactive: {0}", inactive.list == null ? 0 : inactive.list.Count), SystemFonts.DefaultFont, Brushes.Green, x, 4.0f); x += 100.0f; gr.DrawString(string.Format("Active: {0}", active.list == null ? 0 : active.list.Count), SystemFonts.DefaultFont, Brushes.Green, x, 4.0f); x += 70.0f; gr.DrawString(string.Format("Zombie Speed: {0}", worldInfo.zombieSpeed), SystemFonts.DefaultFont, Brushes.Green, x, 4.0f); x += 100.0f; } } return(bm); }
public Graphics(System.Drawing.Graphics renderTarget) { this.renderTarget = renderTarget; }
public virtual void Export(GridVirtual grid, System.Drawing.Graphics graphics, Range rangeToExport, System.Drawing.Point destinationLocation) { if (rangeToExport.IsEmpty()) { return; } System.Drawing.Point cellPoint = destinationLocation; System.Drawing.Point deltaPoint = destinationLocation; using (DevAge.Drawing.GraphicsCache graphicsCache = new DevAge.Drawing.GraphicsCache(graphics)) { for (int r = rangeToExport.Start.Row; r <= rangeToExport.End.Row; r++) { int rowHeight = grid.Rows.GetHeight(r); for (int c = rangeToExport.Start.Column; c <= rangeToExport.End.Column; c++) { Rectangle cellRectangle; Position pos = new Position(r, c); Size cellSize = new Size(grid.Columns.GetWidth(c), rowHeight); Range range = grid.PositionToCellRange(pos); //support for RowSpan or ColSpan //Note: for now I draw only the merged cell at the first position // (this can cause a problem if you export partial range that contains a partial merged cells) if (range.ColumnsCount > 1 || range.RowsCount > 1) { //Is the first position if (range.Start == pos) { Size rangeSize = grid.RangeToSize(range); cellRectangle = new Rectangle(cellPoint, rangeSize); } else { cellRectangle = Rectangle.Empty; } } else { cellRectangle = new Rectangle(cellPoint, cellSize); } if (cellRectangle.IsEmpty == false) { Cells.ICellVirtual cell = grid.GetCell(pos); CellContext context = new CellContext(grid, pos, cell); ExportCell(context, graphicsCache, cellRectangle); } cellPoint = new Point(cellPoint.X + cellSize.Width, cellPoint.Y); } cellPoint = new Point(destinationLocation.X, cellPoint.Y + rowHeight); } } }