示例#1
0
        private void ExportViaFreeImage(Metafile metafile, double width, double height)
        {
            Logger.Info("ExportViaFreeImage: Preset: {0}", Preset);
            Logger.Info("ExportViaFreeImage: Width: {0}; height: {1}", width, height);
            // Calculate the number of pixels needed for the requested
            // output size and resolution; size is given in points (1/72 in),
            // resolution is given in dpi.
            int px = (int)Math.Round(width / 72 * Preset.Dpi);
            int py = (int)Math.Round(height / 72 * Preset.Dpi);

            Logger.Info("ExportViaFreeImage: Pixels: x: {0}; y: {1}", px, py);
            Cancelling      += Exporter_Cancelling;
            PercentCompleted = 10;
            _tiledBitmap     = new TiledBitmap(px, py);
            FreeImageBitmap fib = _tiledBitmap.CreateFreeImageBitmap(metafile, EffectiveTransparency());

            ConvertColor(fib);
            fib.SetResolution(Preset.Dpi, Preset.Dpi);
            fib.Comment      = Versioning.SemanticVersion.Current.BrandName;
            PercentCompleted = 30;
            Logger.Info("ExportViaFreeImage: Saving {0} file", Preset.FileType);
            try
            {
                fib.Save(
                    FileName,
                    Preset.FileType.ToFreeImageFormat(),
                    GetSaveFlags()
                    );
            }
            catch (Exception e)
            {
                Logger.Fatal("ExportViaFreeImage: FreeImageBitmap.Save() threw an exception!");
                Logger.Fatal(e);
                throw;
            }
            finally
            {
                Cancelling      -= Exporter_Cancelling;
                PercentCompleted = 50;
            }
        }