PurplePen.MapDisplay.UpdateDimmedBitmap C# (CSharp) Method

UpdateDimmedBitmap() public method

public UpdateDimmedBitmap ( ) : void
return void
        public void UpdateDimmedBitmap()
        {
            if (dimmedBitmap != null)
                dimmedBitmap.Dispose();
            dimmedBitmap = null;

            // Only dim bitmap if size isn't too large. Otherwise takes too much memory.
            if ((mapType == MapType.Bitmap || mapType == MapType.PDF) && mapIntensity < 0.99F && (bitmap.PixelWidth * bitmap.PixelHeight) < 36000000) {
                Bitmap dimmed = null;
                try {
                    dimmed = new Bitmap(bitmap.PixelWidth, bitmap.PixelHeight);
                }
                catch (Exception) {
                    return;  // typically because not enough memory. Uses alternate dimming method.
                }

                Graphics g = Graphics.FromImage(dimmed);
                ImageAttributes imageAttributes = new ImageAttributes();
                imageAttributes.SetColorMatrix(ComputeColorMatrix());
                g.DrawImage(((GDIPlus_Bitmap)bitmap).Bitmap, new Rectangle(0, 0, bitmap.PixelWidth, bitmap.PixelHeight), 0, 0, bitmap.PixelWidth, bitmap.PixelHeight, GraphicsUnit.Pixel, imageAttributes);
                g.Dispose();

                dimmedBitmap = new GDIPlus_Bitmap(dimmed);
            }
            else {
                dimmedBitmap = null;
            }
        }

Usage Example

Example #1
0
        RectangleF?printArea;                       // print area to display, or null for none.

        // Clones this map display.
        public MapDisplay Clone()
        {
            MapDisplay newMapDisplay = (MapDisplay)MemberwiseClone();

            newMapDisplay.dimmedBitmap = null;         // clones should not share dimmed bitmaps.
            newMapDisplay.UpdateDimmedBitmap();

            return(newMapDisplay);
        }