Exemplo n.º 1
0
 private static void AdjustFrameToImage(RectangleD frame, Image image)
 {
     if (frame.Left < 0)
     {
         frame.Width += frame.Left;
         frame.Left   = 0;
     }
     if (frame.Top < 0)
     {
         frame.Height += frame.Top;
         frame.Top     = 0;
     }
     if (frame.Right > image.Width)
     {
         frame.Width -= frame.Right - image.Width;
     }
     if (frame.Bottom > image.Height)
     {
         frame.Height -= frame.Bottom - image.Height;
     }
 }
Exemplo n.º 2
0
        // todo: skip showRouteLine parameter, use RouteDrawingMode instead
        public Bitmap CreateMapAndRouteImage(bool showRouteLine, double zoomValue, Session sessionToDraw, List <int> legsToDraw, double frameWidth, WaypointAttribute colorCodingAttribute, WaypointAttribute?secondaryColorCodingAttribute, RouteDrawingMode mode, SessionSettings sessionSettings)
        {
            RectangleD frame = GetFrame(zoomValue, sessionToDraw, legsToDraw, frameWidth, colorCodingAttribute, mode);

            var sc = new SessionCollection();

            sc.Add(sessionToDraw);
            var wholeImage = CreateMapAndRouteImage(true, zoomValue, sc, colorCodingAttribute, secondaryColorCodingAttribute, mode, sessionSettings);

            AdjustFrameToImage(frame, wholeImage);

            var croppedImage = new Bitmap(
                Convert.ToInt32(Math.Ceiling(frame.Right) - Math.Floor(frame.Left)),
                Convert.ToInt32(Math.Ceiling(frame.Bottom) - Math.Floor(frame.Top)));
            var croppedImageGraphics = Graphics.FromImage(croppedImage);

            croppedImageGraphics.DrawImage(
                wholeImage,
                -Convert.ToInt32(Math.Floor(frame.Left)),
                -Convert.ToInt32(Math.Floor(frame.Top)));
            croppedImageGraphics.Dispose();
            wholeImage.Dispose();
            return(croppedImage);
        }