PurplePen.MapDisplay.Draw C# (CSharp) Method

Draw() public method

public Draw ( Bitmap bitmap, Matrix transform, Region clipRegion = null ) : void
bitmap System.Drawing.Bitmap
transform Matrix
clipRegion System.Drawing.Region
return void
        public void Draw(Bitmap bitmap, Matrix transform, Region clipRegion = null)
        {
            Debug.Assert(colorModel == ColorModel.CMYK || colorModel == ColorModel.RGB);
            GDIPlus_ColorConverter colorConverter = (colorModel == ColorModel.CMYK) ? new SwopColorConverter() : new GDIPlus_ColorConverter();

            if (bitmap.Height == 0 || bitmap.Width == 0)
                return;

            // Note that courses always drawn full intensity.
            using (var grTargetDimmed = new GDIPlus_BitmapGraphicsTarget(bitmap, CmykColor.FromCmyk(0,0,0,0), transform, colorConverter, mapIntensity))
            using (var grTargetUndimmed = new GDIPlus_BitmapGraphicsTarget(bitmap, null, transform, colorConverter)) {
                float minResolution = GetMinResolution(transform);
                RectangleF clipBounds = grTargetDimmed.Graphics.ClipBounds;
                DrawHelper(grTargetDimmed, grTargetUndimmed, grTargetUndimmed, clipBounds, minResolution);
            }
        }

Same methods

MapDisplay::Draw ( IGraphicsTarget grTarget, RectangleF visRect, float minResolution ) : void

Usage Example

Example #1
0
        // 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);
            }
        }
All Usage Examples Of PurplePen.MapDisplay::Draw