public override void DrawItem(System.Drawing.Graphics graphics) { if (graphics == null) { throw new ArgumentNullException("graphics"); } base.DrawItem(graphics); if (this.ScaleImageToSize) { graphics.DrawImageUnscaled(this.Image,this.StyleDecorator.DisplayRectangle); } else { graphics.DrawImage(this.Image, this.StyleDecorator.DisplayRectangle); } }
public override void OnRender(System.Drawing.Graphics g) { try { var right = m__mercatorProjection.FromPixelToLatLng(new GMap.NET.GPoint(m_gMapControl.Size.Width, 0), (int)m_gMapControl.Zoom); var left = m__mercatorProjection.FromPixelToLatLng(new GMap.NET.GPoint(0, 0), (int)m_gMapControl.Zoom); //var right1 = GeometryTransform.TransformPoint(new SharpMap.Geometries.Point(right.Lng, right.Lat), m_googleMapCoordinateTransformation.MathTransform); //var left1 = GeometryTransform.TransformPoint(new SharpMap.Geometries.Point(left.Lng, left.Lat), m_googleMapCoordinateTransformation.MathTransform); //myMap.Size = new System.Drawing.Size(m_gMapControl.Width, m_gMapControl.Height); //myMap.Zoom = right1.X - left1.X; // 不是Center,具体怎样还没细看 //var p = GoogleMapOffset.GetOffseted(m_gMapControl.CurrentPosition); var p = m_gMapControl.FromLocalToLatLng(m_gMapControl.Size.Width / 2, m_gMapControl.Size.Height / 2); //var p1 = GeometryTransform.TransformPoint(new SharpMap.Geometries.Point(p.Lng, p.Lat), m_googleMapCoordinateTransformation.MathTransform); myMap.Center = new Telogis.GeoBase.LatLon(p.Lat, p.Lng); myMap.Zoom = m_gMapControl.Zoom; var image = myMap.GetMap(); if (image != null) { g.DrawImageUnscaled(image, 0, 0); } //var image = myMap.GetMap(); //var x = m_gMapControl.FromLatLngToLocal(new GMap.NET.PointLatLng(myMap.Envelope.Top, myMap.Envelope.Left)); //var y = m_gMapControl.FromLatLngToLocal(new GMap.NET.PointLatLng(myMap.Envelope.Bottom, myMap.Envelope.Right)); //g.DrawImage(image, x.X, x.Y, y.X - x.X, y.Y - x.Y); } catch (Exception) { } }
public override void Render(System.Drawing.Graphics g, SharpMap.Map map) { base.Render(g, map); Request request = new Request(); request.Map = new EMapRequest.Map(); request.Map.Name = m_MapName; request.User = m_User; request.Pwd = m_Password; request.Version = "2"; request.Type = "eMap.Map"; request.Map.ImageFile = new ImageFile(); request.Map.ImageFile.IncludeInResponse = false; request.Map.ImageFile.IncludeInResponseSpecified = true; request.Map.ImageFile.SizeXSpecified = true; request.Map.ImageFile.SizeX = (ulong)map.Size.Width; request.Map.ImageFile.SizeYSpecified = true; request.Map.ImageFile.SizeY = (ulong)map.Size.Height; request.Map.ImageFile.Format = MapFileFormatEnum.GIF; request.Map.VisibleSection = new VisibleSection(); request.Map.VisibleSection.bottomSpecified = true; request.Map.VisibleSection.bottom = (long)map.Envelope.Min.Y; request.Map.VisibleSection.leftSpecified = true; request.Map.VisibleSection.left = (long)map.Envelope.Min.X; request.Map.VisibleSection.topSpecified = true; request.Map.VisibleSection.top = (long)map.Envelope.Max.Y; request.Map.VisibleSection.rightSpecified = true; request.Map.VisibleSection.right = (long)map.Envelope.Max.X; MapRequest mr = new MapRequest(); mr.Url = m_Url; Response res = mr.ExecuteRequest(request); MemoryStream imageStream = new MemoryStream(res.Image); System.Drawing.Image image = System.Drawing.Image.FromStream(imageStream); g.DrawImageUnscaled(image, 0, 0); }
/// <summary> /// Renders a point to the map. /// </summary> /// <param name="g">Graphics reference</param> /// <param name="point">Point to render</param> /// <param name="symbol">Symbol to place over point</param> /// <param name="symbolscale">The amount that the symbol should be scaled. A scale of '1' equals to no scaling</param> /// <param name="offset">Symbol offset af scale=1</param> /// <param name="rotation">Symbol rotation in degrees</param> /// <param name="map">Map reference</param> public static void DrawPoint(System.Drawing.Graphics g, SharpMap.Geometries.Point point, System.Drawing.Bitmap symbol, float symbolscale, System.Drawing.PointF offset, float rotation, SharpMap.Map map) { if (point == null) return; if (symbol == null) //We have no point style - Use a default symbol symbol = defaultsymbol; System.Drawing.PointF pp = SharpMap.Utilities.Transform.WorldtoMap(point, map); if (rotation != 0 && rotation != float.NaN) { g.TranslateTransform(pp.X, pp.Y); g.RotateTransform(rotation); g.TranslateTransform(-symbol.Width / 2, -symbol.Height / 2); if (symbolscale == 1f) g.DrawImageUnscaled(symbol, (int)(pp.X - symbol.Width / 2 + offset.X), (int)(pp.Y - symbol.Height / 2 + offset.Y)); else { float width = symbol.Width * symbolscale; float height = symbol.Height * symbolscale; g.DrawImage(symbol, (int)pp.X - width / 2 + offset.X * symbolscale, (int)pp.Y - height / 2 + offset.Y * symbolscale, width, height); } g.Transform = map.MapTransform; } else { if (symbolscale == 1f) g.DrawImageUnscaled(symbol, (int)(pp.X - symbol.Width / 2 + offset.X), (int)(pp.Y - symbol.Height / 2 + offset.Y)); else { float width = symbol.Width * symbolscale; float height = symbol.Height * symbolscale; g.DrawImage(symbol, (int)pp.X - width / 2 + offset.X * symbolscale, (int)pp.Y - height / 2 + offset.Y * symbolscale, width, height); } } }
public override void Paint(System.Drawing.Graphics g, EU2.Map.ILightmapDimensions m, System.Drawing.Rectangle area) { if ( sources[srcindex] == null || shaderproxy == null ) return; Rectangle actualarea = m.CoordMap.BlocksToActual( area ); bool decomp = sources[srcindex].VolatileDecompression; sources[srcindex].VolatileDecompression = true; RawImage raw = sources[srcindex].DecodeImage( actualarea ); Bitmap canvas = new Bitmap( raw.Bounds.Width, raw.Bounds.Height, PixelFormat.Format32bppRgb ); BitmapData cdata = canvas.LockBits( new Rectangle( new Point( 0, 0 ), canvas.Size ), ImageLockMode.WriteOnly, canvas.PixelFormat ); int[] lightbuf = shaderproxy.Shade32( raw ); System.Runtime.InteropServices.Marshal.Copy( lightbuf, 0, cdata.Scan0, lightbuf.Length ); canvas.UnlockBits( cdata ); g.DrawImageUnscaled( canvas, 0, 0 ); sources[srcindex].VolatileDecompression = decomp; }
public void ShowChar( System.Drawing.Graphics CurGraphics, System.Char CurChar, System.Int32 Y, System.Int32 X, CharAttribs CurAttribs) { //prntSome.printSome("ShowChar"); if (CurChar == '\0') { return; } System.Drawing.Color CurFGColor = System.Drawing.Color.White; System.Drawing.Color CurBGColor = System.Drawing.Color.Black; this.AssignColors (CurAttribs, ref CurFGColor, ref CurBGColor); if ((CurBGColor != this.BackColor && (this.Modes.Flags & uc_Mode.LightBackground) == 0) || (CurBGColor != this.FGColor && (this.Modes.Flags & uc_Mode.LightBackground) > 0)) { // Erase the current Character underneath the cursor postion this.EraseBuffer.Clear (CurBGColor); // paint a rectangle over the cursor position in the character's BGColor CurGraphics.DrawImageUnscaled ( this.EraseBitmap, X, Y); } if (CurAttribs.IsUnderscored) { CurGraphics.DrawLine (new System.Drawing.Pen (CurFGColor, 1), X, Y + this.UnderlinePos, X + this.CharSize.Width, Y + this.UnderlinePos); } /*VT220*/ /* if ((CurAttribs.IsDECSG == true) && (CurChar == 'l' || CurChar == 'q' || CurChar == 'w' || CurChar == 'k' || CurChar == 'x' || CurChar == 't' || CurChar == 'n' || CurChar == 'u' || CurChar == 'm' || CurChar == 'v' || CurChar == 'j' || CurChar == '`')) { this.ShowSpecialChar ( CurGraphics, CurChar, Y, X, CurFGColor, CurBGColor); return; }*/ /**/ //ANSI if ((CurAttribs.IsDECSG == true) && (CurChar == 'Z' || CurChar == 'l' || CurChar == 'q' || CurChar == 'D' || CurChar == 'B' || CurChar == '?' || CurChar == '3' || CurChar == 'C' || CurChar == 'E' || CurChar == '4' || CurChar == '@' || CurChar == 'A' || CurChar == 'Y' || CurChar == '`')) { this.ShowSpecialChar( CurGraphics, CurChar, Y, X, CurFGColor, CurBGColor); return; } /**/ //prntSome.add2stringrdb(CurChar.ToString()); CurGraphics.DrawString ( CurChar.ToString (), this.Font, new System.Drawing.SolidBrush (CurFGColor), X - this.DrawStringOffset.X, Y - this.DrawStringOffset.Y); }
private void ShowCaret(System.Drawing.Graphics CurGraphics) { System.Int32 X = this.Caret.Pos.X; System.Int32 Y = this.Caret.Pos.Y; if (this.Caret.IsOff == true) { return; } // paint a rectangle over the cursor position CurGraphics.DrawImageUnscaled ( this.Caret.Bitmap, X * (int) this.CharSize.Width, Y * (int) this.CharSize.Height); // if we don't have a char to redraw then leave if (this.CharGrid[Y][X] == '\0') { return; } CharAttribStruct CurAttribs = new CharAttribStruct (); CurAttribs.UseAltColor = true; CurAttribs.GL = this.AttribGrid[Y][X].GL; CurAttribs.GR = this.AttribGrid[Y][X].GR; CurAttribs.GS = this.AttribGrid[Y][X].GS; if (this.AttribGrid[Y][X].UseAltBGColor == false) { CurAttribs.AltColor = this.BackColor; } else if (this.AttribGrid[Y][X].UseAltBGColor == true) { CurAttribs.AltColor = this.AttribGrid[Y][X].AltBGColor; } CurAttribs.IsUnderscored = this.AttribGrid[Y][X].IsUnderscored; CurAttribs.IsDECSG = this.AttribGrid[Y][X].IsDECSG; // redispay the current char in the background colour this.ShowChar ( CurGraphics, this.CharGrid[Y][X], Caret.Pos.Y * this.CharSize.Height, Caret.Pos.X * this.CharSize.Width, CurAttribs); }
/// <summary> /// Renders a point to the map. /// </summary> /// <param name="g">Graphics reference</param> /// <param name="point">Point to render</param> /// <param name="symbol">Symbol to place over point</param> /// <param name="symbolscale">The amount that the symbol should be scaled. A scale of '1' equals to no scaling</param> /// <param name="offset">Symbol offset af scale=1</param> /// <param name="rotation">Symbol rotation in degrees</param> /// <param name="map">Map reference</param> public static void DrawPoint(System.Drawing.Graphics g, SharpMap.Geometries.Point point, System.Drawing.Bitmap symbol, float symbolscale, System.Drawing.PointF offset, float rotation, SharpMap.Map map) { if (point == null) return; if (symbol == null) //We have no point style - Use a default symbol symbol = defaultsymbol; System.Drawing.PointF pp = SharpMap.Utilities.Transform.WorldtoMap(point, map); Matrix startingTransform = g.Transform; if (rotation != 0 && !Single.IsNaN(rotation)) { System.Drawing.PointF rotationCenter = System.Drawing.PointF.Add(pp, new System.Drawing.SizeF(symbol.Width / 2, symbol.Height / 2)); Matrix transform = new Matrix(); transform.RotateAt(rotation, rotationCenter); g.Transform = transform; if (symbolscale == 1f) g.DrawImageUnscaled(symbol, (int)(pp.X - symbol.Width / 2 + offset.X), (int)(pp.Y - symbol.Height / 2 + offset.Y)); else { float width = symbol.Width * symbolscale; float height = symbol.Height * symbolscale; g.DrawImage(symbol, (int)pp.X - width / 2 + offset.X * symbolscale, (int)pp.Y - height / 2 + offset.Y * symbolscale, width, height); } g.Transform = startingTransform; } else { if (symbolscale == 1f) g.DrawImageUnscaled(symbol, (int)(pp.X - symbol.Width / 2 + offset.X), (int)(pp.Y - symbol.Height / 2 + offset.Y)); else { float width = symbol.Width * symbolscale; float height = symbol.Height * symbolscale; g.DrawImage(symbol, (int)pp.X - width / 2 + offset.X * symbolscale, (int)pp.Y - height / 2 + offset.Y * symbolscale, width, height); } } }
/// <summary> /// Draws the current state of the track bar to the specified graphics context with a given alpha level. /// </summary> public void DrawTrackBar(System.Drawing.Graphics g, int alpha) { if (alpha >= 255) { // if the alpha value is 255, skip the secondary buffer since the primary buffer has exactly what we need! g.DrawImageUnscaled(this.Buffer, _clientBounds.Location); } else if (alpha > 0) { // if the alpha value is 0, we don't need to draw anything! Bitmap source = this.Buffer; Bitmap buffer = new Bitmap(source.Width, source.Height, PixelFormat.Format32bppArgb); Rectangle rectangle = new Rectangle(Point.Empty, source.Size); BitmapData sourceData = source.LockBits(rectangle, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); BitmapData bufferData = buffer.LockBits(rectangle, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); try { unsafe { int length = sourceData.Height*sourceData.Stride; byte* sourceDataArray = (byte*) sourceData.Scan0.ToPointer(); byte* bufferDataArray = (byte*) bufferData.Scan0.ToPointer(); for (int n = 0; n < length; n += 4) { bufferDataArray[n + 0] = sourceDataArray[n + 0]; bufferDataArray[n + 1] = sourceDataArray[n + 1]; bufferDataArray[n + 2] = sourceDataArray[n + 2]; bufferDataArray[n + 3] = (byte) (alpha*(sourceDataArray[n + 3]/255f)); } } } finally { source.UnlockBits(sourceData); buffer.UnlockBits(bufferData); } g.DrawImageUnscaled(buffer, _clientBounds.Location); } }
public override void Render(System.Drawing.Graphics g, SharpMap.Map map) { base.Render(g, map); Ptv.Controls.Map.XMap.XMapWSService svcMap = new Ptv.Controls.Map.XMap.XMapWSService(); svcMap.Url = m_Url; if (!string.IsNullOrEmpty(User) && !string.IsNullOrEmpty(Password)) svcMap.Credentials = new NetworkCredential(User, Password); BoundingBox bb = new BoundingBox(); bb.leftTop = new Point(); bb.leftTop.point = new PlainPoint(); bb.leftTop.point.x = map.Envelope.Min.X; bb.leftTop.point.y = map.Envelope.Max.Y; bb.rightBottom = new Point(); bb.rightBottom.point = new PlainPoint(); bb.rightBottom.point.x = map.Envelope.Max.X; bb.rightBottom.point.y = map.Envelope.Min.Y; MapParams mapParams = new MapParams(); mapParams.showScale = true; mapParams.useMiles = false; ImageInfo imageInfo = new ImageInfo(); imageInfo.format = ImageFileFormat.PNG; imageInfo.height = map.Size.Height; imageInfo.width = map.Size.Width; switch (m_xMapServerMode) { case XMapServerMode.All: { Ptv.Controls.Map.XMap.Map xmap = svcMap.renderMapBoundingBox(bb, mapParams, imageInfo, null, true, null); MemoryStream imageStream = new MemoryStream(xmap.image.rawImage); System.Drawing.Image image = System.Drawing.Image.FromStream(imageStream); System.Drawing.Bitmap bmp = image as System.Drawing.Bitmap; bmp.MakeTransparent(System.Drawing.Color.FromArgb(255, 254, 185)); g.DrawImageUnscaled(image, 0, 0); return; } case XMapServerMode.BackGround: { // render only backgound and street StaticLayer slTown = new StaticLayer(); slTown.visible = false; slTown.name = "town"; slTown.detailLevel = 0; slTown.category = -1; StaticLayer slStreet = new StaticLayer(); slStreet.visible = true; slStreet.name = "street"; slStreet.detailLevel = 0; slStreet.category = -1; StaticLayer slBackground = new StaticLayer(); slBackground.visible = true; slBackground.name = "background"; slBackground.detailLevel = 0; slBackground.category = -1; Ptv.Controls.Map.XMap.Layer[] arrLayer = new Ptv.Controls.Map.XMap.Layer[] { slBackground, slStreet, slTown }; Ptv.Controls.Map.XMap.Map xmap = svcMap.renderMapBoundingBox(bb, mapParams, imageInfo, arrLayer, true, null); MemoryStream imageStream = new MemoryStream(xmap.image.rawImage); System.Drawing.Image image = System.Drawing.Image.FromStream(imageStream); System.Drawing.Bitmap bmp = image as System.Drawing.Bitmap; g.DrawImageUnscaled(image, 0, 0); return; } case XMapServerMode.Overlay: { // render only town StaticLayer slTown = new StaticLayer(); slTown.visible = true; slTown.name = "town"; slTown.detailLevel = 0; slTown.category = -1; StaticLayer slStreet = new StaticLayer(); slStreet.visible = false; slStreet.name = "street"; slStreet.detailLevel = 0; slStreet.category = -1; StaticLayer slBackground = new StaticLayer(); slBackground.visible = false; slBackground.name = "background"; slBackground.detailLevel = 0; slBackground.category = -1; Ptv.Controls.Map.XMap.Layer[] arrLayer = new Ptv.Controls.Map.XMap.Layer[] { slBackground, slStreet, slTown }; Ptv.Controls.Map.XMap.Map xmap = svcMap.renderMapBoundingBox(bb, mapParams, imageInfo, arrLayer, true, null); MemoryStream imageStream = new MemoryStream(xmap.image.rawImage); System.Drawing.Image image = System.Drawing.Image.FromStream(imageStream); System.Drawing.Bitmap bmp = image as System.Drawing.Bitmap; // make map background color transparent bmp.MakeTransparent(System.Drawing.Color.FromArgb(255, 254, 185)); g.DrawImageUnscaled(image, 0, 0); return; } } }
internal static void PaintSystemButton(System.Drawing.Graphics g, SystemButton btn, Rectangle r, bool MouseDown, bool MouseOver, bool Disabled) { // Draw state if any if (MouseDown) { g.FillRectangle(new SolidBrush(ColorFunctions.PressedBackColor(g)), r); NativeFunctions.DrawRectangle(g, SystemPens.Highlight, r); } else if (MouseOver) { g.FillRectangle(new SolidBrush(ColorFunctions.HoverBackColor(g)), r); NativeFunctions.DrawRectangle(g, SystemPens.Highlight, r); } Bitmap bmp = new Bitmap(r.Width, r.Height, g); Graphics gBmp = Graphics.FromImage(bmp); Rectangle rBtn = new Rectangle(0, 0, r.Width, r.Height); rBtn.Inflate(0, -1); Rectangle rClip = rBtn; rClip.Inflate(-1, -1); using (SolidBrush brush = new SolidBrush(SystemColors.Control)) gBmp.FillRectangle(brush, 0, 0, r.Width, r.Height); gBmp.SetClip(rClip); System.Windows.Forms.ControlPaint.DrawCaptionButton(gBmp, rBtn, (System.Windows.Forms.CaptionButton)btn, System.Windows.Forms.ButtonState.Flat); gBmp.ResetClip(); gBmp.Dispose(); bmp.MakeTransparent(SystemColors.Control); if (Disabled) { float[][] array = new float[5][]; array[0] = new float[5] { 0, 0, 0, 0, 0 }; array[1] = new float[5] { 0, 0, 0, 0, 0 }; array[2] = new float[5] { 0, 0, 0, 0, 0 }; array[3] = new float[5] { .5f, .5f, .5f, .5f, 0 }; array[4] = new float[5] { 0, 0, 0, 0, 0 }; System.Drawing.Imaging.ColorMatrix grayMatrix = new System.Drawing.Imaging.ColorMatrix(array); System.Drawing.Imaging.ImageAttributes disabledImageAttr = new System.Drawing.Imaging.ImageAttributes(); disabledImageAttr.ClearColorKey(); disabledImageAttr.SetColorMatrix(grayMatrix); g.DrawImage(bmp, r, 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, disabledImageAttr); } else { if (MouseDown) r.Offset(1, 1); g.DrawImageUnscaled(bmp, r); } }
protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); if (this.Icon != null) { System.Drawing.Drawing2D.GraphicsContainer container = graphics.BeginContainer(); graphics.SetClip(cellBounds); // Point p = new Point(); p = cellBounds.Location; p.Offset(iconLeftPad, iconTopPad); graphics.DrawImageUnscaled(this.Icon, p); graphics.EndContainer(container); } }
public override void DrawItem(System.Drawing.Graphics g, ImageListViewItem item, ItemState state, System.Drawing.Rectangle bounds) { using (Brush bItemBack = new SolidBrush(item.BackColor)) g.FillRectangle(bItemBack, bounds); Size itemPadding = new Size(2, 2); Image img = item.ThumbnailImage; if (img != null) { Rectangle border = new Rectangle(bounds.Location + itemPadding, ImageListView.ThumbnailSize); Rectangle pos = GetSizedImageBounds(img, border); g.DrawImage(img, pos); // Draw image border if (ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None)) { using (Pen pen = new Pen(SystemColors.Highlight, 3)) { g.DrawRectangle(pen, border); } } else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None)) { using (Pen pen = new Pen(SystemColors.GrayText, 3)) { pen.Alignment = System.Drawing.Drawing2D.PenAlignment.Center; g.DrawRectangle(pen, border); } } else { using (Pen pGray128 = new Pen(Color.FromArgb(128, SystemColors.GrayText))) { g.DrawRectangle(pGray128, border); } } stPreview st = (stPreview)item.Tag; if (st.State == stPreview.DownloadState.Downloading) g.DrawImageUnscaled(OtakuImage.Properties.Resources.downloading, border.Left + 5, border.Top + 5); else if (st.State == stPreview.DownloadState.Waiting) g.DrawImageUnscaled(OtakuImage.Properties.Resources.waiting, border.Left + 5, border.Top + 5); else if (st.State == stPreview.DownloadState.Complete) g.DrawImageUnscaled(OtakuImage.Properties.Resources.complete, border.Left + 5, border.Top + 5); else if (st.State == stPreview.DownloadState.Error) g.DrawImageUnscaled(OtakuImage.Properties.Resources.err, border.Left + 5, border.Top + 5); } }
internal void DrawOn(System.Drawing.Graphics g) { g.DrawImageUnscaled(bitmap, Bounds.Location); }
/// <summary> /// Updates the line indicating the angle. /// </summary> void UpdateAngle(System.Drawing.Graphics g) { var x = Width - 40; var fill = Enabled ? System.Drawing.Brushes.Black : System.Drawing.Brushes.LightGray; var line = Enabled ? Pens.White : Pens.LightGray; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed; g.FillEllipse(fill, x + 4, 4, 32, 32); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; if (_elevation > 0) { // Draw a single pixel in the center - a bit of a pain to do var pt = new Bitmap(1, 1); pt.SetPixel(0, 0, Color.White); g.DrawImageUnscaled(pt, 20, 20); pt.Dispose(); } else { var xcoord = x + (int)Math.Round(Math.Cos(_angle) * 15, 0) + 20; var ycoord = -(int)Math.Round(Math.Sin(_angle) * 15, 0) + 20; g.DrawLine(line, x + 20, 20, xcoord, ycoord); } }
public override void Render(System.Drawing.Graphics g, Map map) { SharpMap.Web.Wms.Client.WmsOnlineResource resource = GetPreferredMethod(); Uri myUri = new Uri(GetRequestUrl(map.Envelope, map.Size)); System.Net.WebRequest myWebRequest = System.Net.WebRequest.Create(myUri); myWebRequest.Method = resource.Type; myWebRequest.Timeout = _TimeOut; if (_Credentials != null) myWebRequest.Credentials = _Credentials; else myWebRequest.Credentials = System.Net.CredentialCache.DefaultCredentials; if (_Proxy != null) myWebRequest.Proxy = _Proxy; try { System.Net.HttpWebResponse myWebResponse = (System.Net.HttpWebResponse)myWebRequest.GetResponse(); System.IO.Stream dataStream = myWebResponse.GetResponseStream(); if (myWebResponse.ContentType.StartsWith("image")) { System.Drawing.Image img = System.Drawing.Image.FromStream(myWebResponse.GetResponseStream()); if (_ImageAttributes != null) g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, this.ImageAttributes); else g.DrawImageUnscaled(img, 0, 0, map.Size.Width, map.Size.Height); } dataStream.Close(); myWebResponse.Close(); } catch (System.Net.WebException webEx) { if (!_ContinueOnError) throw (new SharpMap.Rendering.Exceptions.RenderException("There was a problem connecting to the WMS server when rendering layer '" + this.LayerName + "'", webEx)); else //Write out a trace warning instead of throwing an error to help debugging WMS problems System.Diagnostics.Trace.Write("There was a problem connecting to the WMS server when rendering layer '" + this.LayerName + "': " + webEx.Message); } catch (System.Exception ex) { if (!_ContinueOnError) throw (new SharpMap.Rendering.Exceptions.RenderException("There was a problem rendering layer '" + this.LayerName + "'", ex)); else //Write out a trace warning instead of throwing an error to help debugging WMS problems System.Diagnostics.Trace.Write("There was a problem connecting to the WMS server when rendering layer '" + this.LayerName + "': " + ex.Message); } base.Render(g, map); }
/// <summary> /// Draws the current state of the track bar to the specified graphics context with a given alpha level. /// </summary> public void DrawTrackBar(System.Drawing.Graphics g, int alpha) { // if the alpha value is 0, we don't need to draw anything! if (alpha <= 0) return; Bitmap source = this.Buffer; if (alpha >= 255) { // if the alpha value is 255, skip the secondary buffer since the primary buffer has exactly what we need! g.DrawImageUnscaled(source, _clientBounds.Location); } else { Bitmap buffer = new Bitmap(source.Width, source.Height, PixelFormat.Format32bppArgb); Rectangle rectangle = new Rectangle(Point.Empty, source.Size); BitmapData sourceData = source.LockBits(rectangle, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); BitmapData bufferData = buffer.LockBits(rectangle, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); try { unsafe { float sAlpha = alpha/255f; int length = sourceData.Height*sourceData.Stride/4; int* sourceDataArray = (int*)sourceData.Scan0.ToPointer(); int* bufferDataArray = (int*)bufferData.Scan0.ToPointer(); for (int n = 0; n < length; ++n) { int value = *(sourceDataArray++); *(bufferDataArray++) = (value & 0x00FFFFFF) | ((byte) (((value >> 24) & 0x0FF)*sAlpha) << 24); } } } finally { source.UnlockBits(sourceData); buffer.UnlockBits(bufferData); } g.DrawImageUnscaled(buffer, _clientBounds.Location); } }
// renders links between vertices and directon markers void RenderLinks(GraphController<int, int> g, System.Drawing.Graphics gdi,Control[] ctrls) { Bitmap buffer = new Bitmap((int)gdi.VisibleClipBounds.Width, (int)gdi.VisibleClipBounds.Height); Graphics localg = Graphics.FromImage(buffer); localg.SmoothingMode = gdi.SmoothingMode; List<Rectangle> points = new List<Rectangle>(); Pen pen = new Pen(Brushes.Black, 2); Brush br = Brushes.Gray; for (int i = 0; i < g.VertexCount; i++) for (int j = 0; j < g.VertexCount; j++) { if (!g.EdgeExists(i, j)) continue; Control c1 = GetControlbyName(i.ToString(), ctrls); Control c2 = GetControlbyName(j.ToString(), ctrls); Point p1 = c1.Location + new Size(c1.Size.Width / 2, c1.Size.Height / 2); Point p2 = c2.Location + new Size(c2.Size.Width / 2, c2.Size.Height / 2); //gdi.DrawLine(pen, p1, p2); localg.DrawLine(pen, p1, p2); points.Add(new Rectangle(p2 - new Size((int)(0.199 * (p2.X - p1.X)) + 5, (int)(0.199 * (p2.Y - p1.Y)) + 5), new Size(10, 10))); } if (g.IsDirected) { foreach (Rectangle r in points) { //gdi.FillEllipse(br, r); localg.FillEllipse(br, r); } } gdi.Clear(Color.White); gdi.DrawImageUnscaled(buffer, 0, 0); }