// For bitmap or PDF background, write the bitmap to the given file with the given format. public void WriteBitmapMap(string fileName, ImageFormat format, out float dpi) { dpi = this.bitmapDpi; Bitmap bmp = ((GDIPlus_Bitmap)bitmap).Bitmap; BitmapUtil.SaveBitmap(bmp, fileName, format); }
// Create a bitmap file of the mapDisplay supplied at construction. // If mapperForWorldFile is not null and real world coords are defined, also create a world file. public void CreateBitmap(string fileName, RectangleF rect, ImageFormat imageFormat, float dpi, CoordinateMapper mapperForWorldFile) { float bitmapWidth, bitmapHeight; // size of the bitmap in pixels. int pixelWidth, pixelHeight; // bitmapWidth/Height, rounded up to integer. bitmapWidth = (rect.Width / 25.4F) * dpi; bitmapHeight = (rect.Height / 25.4F) * dpi; pixelWidth = (int)Math.Ceiling(bitmapWidth); pixelHeight = (int)Math.Ceiling(bitmapHeight); Bitmap bitmap = new Bitmap(pixelWidth, pixelHeight, PixelFormat.Format24bppRgb); bitmap.SetResolution(dpi, dpi); // Set the transform Matrix transform = Geometry.CreateInvertedRectangleTransform(rect, new RectangleF(0, 0, bitmapWidth, bitmapHeight)); // And draw. mapDisplay.Draw(bitmap, transform); // JPEG and GIF have special code paths because the default Save method isn't // really good enough. if (imageFormat == ImageFormat.Jpeg) { BitmapUtil.SaveJpeg(bitmap, fileName, 80); } else if (imageFormat == ImageFormat.Gif) { BitmapUtil.SaveGif(bitmap, fileName); } else { bitmap.Save(fileName, imageFormat); } bitmap.Dispose(); if (mapperForWorldFile != null && mapperForWorldFile.HasRealWorldCoords) { string extension = Path.GetExtension(fileName); string worldFileName = Path.ChangeExtension(fileName, WorldFileExtension(extension)); CreateWorldFile(worldFileName, rect, bitmapWidth, bitmapHeight, mapperForWorldFile); } }
// Write all the image bitmaps. Also updates the file names in the templates to the full path names. private void WriteImageBitmaps(Map map) { using (map.Write()) { List <TemplateInfo> templates = new List <TemplateInfo>(map.Templates); foreach (BitmapToWrite bitmapToWrite in BitmapsToWrite()) { BitmapUtil.SaveBitmap(bitmapToWrite.Bitmap, bitmapToWrite.FullPath, bitmapToWrite.Format); for (int i = 0; i < templates.Count; ++i) { if (templates[i].absoluteFileName == bitmapToWrite.Name) { templates[i] = templates[i].UpdateFileName(bitmapToWrite.FullPath); } } } map.Templates = templates; } }