// Render part of a map to a bitmap. static BitmapSource RenderBitmap(Map map, int bmWidth, int bmHeight, RectangleF mapArea) { // Calculate the transform matrix. Point midpoint = new Point(bmWidth / 2.0F, bmHeight / 2.0F); double scaleFactor = bmWidth / mapArea.Width; PointF centerPoint = new PointF((mapArea.Left + mapArea.Right) / 2, (mapArea.Top + mapArea.Bottom) / 2); Matrix matrix = Matrix.Identity; matrix.TranslatePrepend(midpoint.X, midpoint.Y); matrix.ScalePrepend(scaleFactor, -scaleFactor); // y scale is negative to get to cartesian orientation. matrix.TranslatePrepend(-centerPoint.X, -centerPoint.Y); // Get the render options. RenderOptions renderOpts = new RenderOptions(); renderOpts.usePatternBitmaps = false; renderOpts.minResolution = (float) (1 / scaleFactor); // Create a drawing of the map. DrawingVisual visual = new DrawingVisual(); DrawingContext dc = visual.RenderOpen(); // Clear the bitmap dc.DrawRectangle(Brushes.White, null, new Rect(-1, -1, bmWidth + 2, bmHeight + 2)); // clear background. // Transform to map coords. dc.PushTransform(new MatrixTransform(matrix)); // Draw the map. using (map.Read()) map.Draw(dc, mapArea, renderOpts); dc.Close(); // Draw into a new bitmap. RenderTargetBitmap bitmapNew = new RenderTargetBitmap(bmWidth, bmHeight, 96.0, 96.0, PixelFormats.Pbgra32); bitmapNew.Render(visual); bitmapNew.Freeze(); return bitmapNew; }
public void Offset(PointF pos) { left += pos.X; top += pos.Y; }
public RectangleF(PointF location, SizeF size) { this.left = location.X; this.top = location.Y; this.width = size.Width; this.height = size.Height; }
public bool Contains(PointF pt) { return Contains(pt.X, pt.Y); }