// Update the dimmed bitmap. If the intensity is < 1 and we're using a bitmap, dim it. 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; } }