Example #1
0
        // 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;
            }
        }
Example #2
0
        // Set the map file used to draw.
        public void SetMapFile(MapType newMapType, string newFilename)
        {
            this.mapType  = newMapType;
            this.filename = newFilename;
            this.bitmap   = null;
            this.map      = null;

            if (newMapType == MapType.None)
            {
                map        = null;
                mapVersion = new MapFileFormat(MapFileFormatKind.None, 0);
                bitmap     = null;
                pdfMapFile = null;
            }
            else if (newMapType == MapType.OCAD)
            {
                map        = new Map(MapUtil.TextMetricsProvider, new GDIPlus_FileLoader(Path.GetDirectoryName(newFilename)));
                mapVersion = InputOutput.ReadFile(newFilename, map);
                bitmap     = null;
                pdfMapFile = null;
            }
            else if (newMapType == MapType.Bitmap)
            {
                map        = null;
                mapVersion = new MapFileFormat(MapFileFormatKind.None, 0);
                Bitmap bm = (Bitmap)Image.FromFile(newFilename);
                bitmap     = new GDIPlus_Bitmap(bm);
                bitmapDpi  = bm.HorizontalResolution;
                pdfMapFile = null;
            }
            else if (newMapType == MapType.PDF)
            {
                string errorText;
                map        = null;
                mapVersion = new MapFileFormat(MapFileFormatKind.None, 0);
                Size bitmapSize;
                pdfMapFile = MapUtil.ValidatePdf(newFilename, out bitmapDpi, out bitmapSize, out errorText);
                if (pdfMapFile == null)
                {
                    this.mapType = MapType.None;
                    bitmap       = null;
                }
                else
                {
                    Bitmap bm = (Bitmap)Image.FromFile(pdfMapFile.PngFileName);
                    bitmap = new GDIPlus_Bitmap(bm);
                }
            }
            else
            {
                Debug.Fail("bad maptype");
            }

            UpdateDimmedBitmap();
            RaiseChanged(null);        // redraw everything.
        }
Example #3
0
        // 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;
            }
        }
Example #4
0
        // Set the map file used to draw.
        public void SetMapFile(MapType newMapType, string newFilename)
        {
            this.mapType = newMapType;
            this.filename = newFilename;
            this.bitmap = null;
            this.map = null;

            if (newMapType == MapType.None) {
                map = null;
                mapVersion = new MapFileFormat(MapFileFormatKind.None, 0);
                bitmap = null;
                pdfMapFile = null;
            }
            else if (newMapType == MapType.OCAD) {
                map = new Map(MapUtil.TextMetricsProvider, new GDIPlus_FileLoader(Path.GetDirectoryName(newFilename)));
                mapVersion = InputOutput.ReadFile(newFilename, map);
                bitmap = null;
                pdfMapFile = null;
            }
            else if (newMapType == MapType.Bitmap) {
                map = null;
                mapVersion = new MapFileFormat(MapFileFormatKind.None, 0);
                Bitmap bm = (Bitmap)Image.FromFile(newFilename);
                bitmap = new GDIPlus_Bitmap(bm);
                bitmapDpi = bm.HorizontalResolution;
                pdfMapFile = null;
            }
            else if (newMapType == MapType.PDF) {
                string errorText;
                map = null;
                mapVersion = new MapFileFormat(MapFileFormatKind.None, 0);
                Size bitmapSize;
                pdfMapFile = MapUtil.ValidatePdf(newFilename, out bitmapDpi, out bitmapSize, out errorText);
                if (pdfMapFile == null) {
                    this.mapType = MapType.None;
                    bitmap = null;
                }
                else {
                    Bitmap bm = (Bitmap)Image.FromFile(pdfMapFile.PngFileName);
                    bitmap = new GDIPlus_Bitmap(bm);
                }
            }
            else {
                Debug.Fail("bad maptype");
            }

            UpdateDimmedBitmap();
            RaiseChanged(null);        // redraw everything.
        }