private void CreatePdfOverviewMap(PdfContentByte content, Configuration.PrintTemplateContentRow row) { AppState appState = new AppState(); appState.Application = _appState.Application; Configuration.ApplicationRow application = AppContext.GetConfiguration().Application.First(o => o.ApplicationID == appState.Application); appState.MapTab = application.OverviewMapID; appState.Extent = application.GetFullExtentEnvelope(); int pixelWidth = Convert.ToInt32(row.Width * PixelsPerInch); int pixelHeight = Convert.ToInt32(row.Height * PixelsPerInch); MapMaker mapMaker = new MapMaker(appState, pixelWidth, pixelHeight, 2); MapImageData mapImageData = mapMaker.GetImage(); System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(new MemoryStream(mapImageData.Image)); Transformation trans = new AffineTransformation(pixelWidth * 2, pixelHeight * 2, appState.Extent); MapGraphics mapGraphics = MapGraphics.FromImage(bitmap, trans); double minSize = (trans.Transform(new Coordinate(1, 0)).X - trans.Transform(new Coordinate(0, 0)).X) * 12; Envelope extent = new Envelope(new Coordinate(_appState.Extent.MinX, _appState.Extent.MinY), new Coordinate(_appState.Extent.MaxX, _appState.Extent.MaxY)); if (extent.Width < minSize) { extent = new Envelope(new Coordinate(extent.Centre.X - minSize * 0.5, extent.MinY), new Coordinate(extent.Centre.X + minSize * 0.5, extent.MaxY)); } if (extent.Height < minSize) { extent = new Envelope(new Coordinate(extent.MinX, extent.Centre.Y - minSize * 0.5), new Coordinate(extent.MaxX, extent.Centre.Y + minSize * 0.5)); } System.Drawing.Brush brush = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(64, System.Drawing.Color.Red)); System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Red, 4); mapGraphics.FillEnvelope(brush, extent); mapGraphics.DrawEnvelope(pen, extent); MemoryStream stream = new MemoryStream(); bitmap.Save(stream, mapImageData.Type == CommonImageType.Png ? System.Drawing.Imaging.ImageFormat.Png : System.Drawing.Imaging.ImageFormat.Jpeg); byte[] mapImage = stream.ToArray(); float originX = Convert.ToSingle(row.OriginX) * PointsPerInch; float originY = Convert.ToSingle(row.OriginY) * PointsPerInch; float width = Convert.ToSingle(row.Width) * PointsPerInch; float height = Convert.ToSingle(row.Height) * PointsPerInch; iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(mapImage); image.SetAbsolutePosition(originX, originY); image.ScaleAbsolute(width, height); content.AddImage(image); CreatePdfBox(content, row, false); }
public MapGraphics GetMapGraphics() { Bitmap bitmap = new Bitmap(new MemoryStream(GetImageBytes())); return(MapGraphics.FromImage(bitmap, _extent)); }