/// <summary> /// Initializes a new instance of the <see cref="WpfDrawingSettings"/> /// class with the specified drawing or rendering settings. /// </summary> /// <param name="settings"> /// This specifies the settings used by the rendering or drawing engine. /// If this is <see langword="null"/>, the default settings is used. /// </param> public DirectorySvgConverter(WpfDrawingSettings settings) : base(settings) { _isOverwrite = true; _isRecursive = true; _encoderType = ImageEncoderType.PngBitmap; }
public bool SaveImage(string fileName, DirectoryInfo imageFileDir, ImageEncoderType encoderType) { if (imageFileDir == null) { return(this.SaveImageFile(fileName, String.Empty, encoderType)); } else { if (!imageFileDir.Exists) { imageFileDir.Create(); } string outputExt = GetImageFileExtention(encoderType); string fileNameWithoutExt = Path.GetFileNameWithoutExtension( fileName); string imageFileName = Path.Combine(imageFileDir.FullName, fileNameWithoutExt + outputExt); return(this.SaveImageFile(fileName, imageFileName, encoderType)); } }
public bool SaveImage(string fileName, FileInfo imageFileName, ImageEncoderType encoderType) { return(this.SaveImageFile(fileName, imageFileName == null ? string.Empty : imageFileName.FullName, encoderType)); }
/// <summary> /// /// </summary> /// <param name="encoderType"></param> /// <returns></returns> protected static string GetImageFileExtention(ImageEncoderType encoderType) { switch (encoderType) { case ImageEncoderType.BmpBitmap: return(".bmp"); case ImageEncoderType.GifBitmap: return(".gif"); case ImageEncoderType.JpegBitmap: return(".jpg"); case ImageEncoderType.PngBitmap: return(".png"); case ImageEncoderType.TiffBitmap: return(".tif"); case ImageEncoderType.WmpBitmap: return(".wdp"); } return(".png"); }
/// <summary> /// Initializes a new instance of the <see cref="ImageSvgConverter"/> class /// with the specified drawing or rendering settings and the saving options. /// </summary> /// <param name="saveXaml"> /// This specifies whether to save result object tree in image file. /// </param> /// <param name="saveZaml"> /// This specifies whether to save result object tree in ZAML file. The /// ZAML is simply a G-Zip compressed image format, similar to the SVGZ. /// </param> /// <param name="settings"> /// This specifies the settings used by the rendering or drawing engine. /// If this is <see langword="null"/>, the default settings is used. /// </param> public ImageSvgConverter(bool saveXaml, bool saveZaml, WpfDrawingSettings settings) : base(saveXaml, saveZaml, settings) { _encoderType = ImageEncoderType.PngBitmap; _wpfRenderer = new WpfDrawingRenderer(this.DrawingSettings); _wpfWindow = new WpfSvgWindow(640, 480, _wpfRenderer); }
public ConverterOptions() { _textAsGeometry = true; _includeRuntime = false; _generateImage = false; _generalWpf = true; _saveXaml = true; _saveZaml = false; _customXamlWriter = true; _errorMessage = String.Empty; _encoderType = ImageEncoderType.PngBitmap; }
public ConverterOptions() { _textAsGeometry = true; _includeRuntime = false; _generateImage = false; _generalWpf = true; _saveXaml = true; _saveZaml = false; _customXamlWriter = true; _errorMessage = string.Empty; _encoderType = ImageEncoderType.PngBitmap; }
/// <summary> /// Initializes a new instance of the <see cref="StreamSvgConverter"/> class /// with the specified drawing or rendering settings and the saving options. /// </summary> /// <param name="saveXaml"> /// This specifies whether to save result object tree in image file. /// </param> /// <param name="saveZaml"> /// This specifies whether to save result object tree in ZAML file. The /// ZAML is simply a G-Zip compressed image format, similar to the SVGZ. /// </param> /// <param name="settings"> /// This specifies the settings used by the rendering or drawing engine. /// If this is <see langword="null"/>, the default settings is used. /// </param> public StreamSvgConverter(bool saveXaml, bool saveZaml, WpfDrawingSettings settings) : base(saveXaml, saveZaml, settings) { long pixelWidth = 0; long pixelHeight = 0; if (settings != null && settings.HasPixelSize) { pixelWidth = settings.PixelWidth; pixelHeight = settings.PixelHeight; } _encoderType = ImageEncoderType.PngBitmap; _wpfRenderer = new WpfDrawingRenderer(this.DrawingSettings); _wpfWindow = new WpfSvgWindow(pixelWidth, pixelHeight, _wpfRenderer); }
public ConverterOptions(ConverterOptions source) { if (source == null) { throw new ArgumentNullException("source"); } _textAsGeometry = source._textAsGeometry; _includeRuntime = source._includeRuntime; _generateImage = source._generateImage; _generalWpf = source._generalWpf; _saveXaml = source._saveXaml; _saveZaml = source._saveZaml; _customXamlWriter = source._customXamlWriter; _encoderType = source._encoderType; _errorMessage = source._errorMessage; }
public void Update(ConverterCommandLines commands) { if (commands == null) { return; } _textAsGeometry = commands.TextAsGeometry; _includeRuntime = commands.IncludeRuntime; _saveXaml = commands.SaveXaml; _saveZaml = commands.SaveZaml; _generateImage = commands.SaveImage; _generalWpf = _saveXaml || _saveZaml; _customXamlWriter = commands.UseCustomXamlWriter; if (_generateImage) { switch (commands.Image.ToLower()) { case "bmp": _encoderType = ImageEncoderType.BmpBitmap; break; case "png": _encoderType = ImageEncoderType.PngBitmap; break; case "jpeg": case "jpg": _encoderType = ImageEncoderType.JpegBitmap; break; case "tif": case "tiff": _encoderType = ImageEncoderType.TiffBitmap; break; case "gif": _encoderType = ImageEncoderType.GifBitmap; break; case "wdp": _encoderType = ImageEncoderType.WmpBitmap; break; } } }
private static BitmapEncoder GetBitmapEncoder(string fileExtension, ImageEncoderType encoderType) { BitmapEncoder bitampEncoder = null; switch (encoderType) { case ImageEncoderType.BmpBitmap: bitampEncoder = new BmpBitmapEncoder(); break; case ImageEncoderType.GifBitmap: bitampEncoder = new GifBitmapEncoder(); break; case ImageEncoderType.JpegBitmap: JpegBitmapEncoder jpgEncoder = new JpegBitmapEncoder(); // Set the default/user options... bitampEncoder = jpgEncoder; break; case ImageEncoderType.PngBitmap: PngBitmapEncoder pngEncoder = new PngBitmapEncoder(); // Set the default/user options... bitampEncoder = pngEncoder; break; case ImageEncoderType.TiffBitmap: bitampEncoder = new TiffBitmapEncoder(); break; case ImageEncoderType.WmpBitmap: WmpBitmapEncoder wmpEncoder = new WmpBitmapEncoder(); // Set the default/user options... bitampEncoder = wmpEncoder; break; } if (bitampEncoder == null) { bitampEncoder = new PngBitmapEncoder(); } return(bitampEncoder); }
/// <summary> /// Initializes a new instance of the <see cref="ImageSvgConverter"/> class /// with the specified drawing or rendering settings and the saving options. /// </summary> /// <param name="saveXaml"> /// This specifies whether to save result object tree in image file. /// </param> /// <param name="saveZaml"> /// This specifies whether to save result object tree in ZAML file. The /// ZAML is simply a G-Zip compressed image format, similar to the SVGZ. /// </param> /// <param name="settings"> /// This specifies the settings used by the rendering or drawing engine. /// If this is <see langword="null"/>, the default settings is used. /// </param> public ImageSvgConverter(bool saveXaml, bool saveZaml, WpfDrawingSettings settings) : base(saveXaml, saveZaml, settings) { long pixelWidth = 0; long pixelHeight = 0; if (settings != null) { settings.EnsureViewboxSize = false; settings.IgnoreRootViewbox = true; if (settings.HasPixelSize) { pixelWidth = settings.PixelWidth; pixelHeight = settings.PixelHeight; } } _encoderType = ImageEncoderType.PngBitmap; _wpfRenderer = new WpfDrawingRenderer(this.DrawingSettings); _wpfWindow = new WpfSvgWindow(pixelWidth, pixelHeight, _wpfRenderer); }
private static BitmapEncoder GetBitmapEncoder(string fileExtension, ImageEncoderType encoderType) { BitmapEncoder bitampEncoder = null; switch (encoderType) { case ImageEncoderType.BmpBitmap: bitampEncoder = new BmpBitmapEncoder(); break; case ImageEncoderType.GifBitmap: bitampEncoder = new GifBitmapEncoder(); break; case ImageEncoderType.JpegBitmap: JpegBitmapEncoder jpgEncoder = new JpegBitmapEncoder(); // Set the default/user options... bitampEncoder = jpgEncoder; break; case ImageEncoderType.PngBitmap: PngBitmapEncoder pngEncoder = new PngBitmapEncoder(); // Set the default/user options... bitampEncoder = pngEncoder; break; case ImageEncoderType.TiffBitmap: bitampEncoder = new TiffBitmapEncoder(); break; case ImageEncoderType.WmpBitmap: WmpBitmapEncoder wmpEncoder = new WmpBitmapEncoder(); // Set the default/user options... bitampEncoder = wmpEncoder; break; } if (bitampEncoder == null) { bitampEncoder = new PngBitmapEncoder(); } return bitampEncoder; }
private bool SaveImageFile(string fileName, string imageFileName, ImageEncoderType encoderType) { if (_drawing == null) { throw new InvalidOperationException( "There is no converted drawing for the saving operation."); } string outputExt = GetImageFileExtention(encoderType); string outputFileName = null; if (string.IsNullOrWhiteSpace(imageFileName)) { string fileNameWithoutExt = Path.GetFileNameWithoutExtension(fileName); string workingDir = Path.GetDirectoryName(fileName); outputFileName = Path.Combine(workingDir, fileNameWithoutExt + outputExt); } else { string fileExt = Path.GetExtension(imageFileName); if (string.IsNullOrWhiteSpace(fileExt)) { outputFileName = imageFileName + outputExt; } else if (!string.Equals(fileExt, outputExt, StringComparison.OrdinalIgnoreCase)) { outputFileName = Path.ChangeExtension(imageFileName, outputExt); } else { outputFileName = imageFileName; } } string outputFileDir = Path.GetDirectoryName(outputFileName); if (!Directory.Exists(outputFileDir)) { Directory.CreateDirectory(outputFileDir); } BitmapEncoder bitampEncoder = GetBitmapEncoder(encoderType); // The image parameters... Rect drawingBounds = _drawing.Bounds; int pixelWidth = (int)drawingBounds.Width; int pixelHeight = (int)drawingBounds.Height; double dpiX = 96; double dpiY = 96; // The Visual to use as the source of the RenderTargetBitmap. DrawingVisual drawingVisual = new DrawingVisual(); DrawingContext drawingContext = drawingVisual.RenderOpen(); if (this.Background != null) { drawingContext.DrawRectangle(this.Background, null, _drawing.Bounds); } drawingContext.DrawDrawing(_drawing); drawingContext.Close(); // The BitmapSource that is rendered with a Visual. RenderTargetBitmap targetBitmap = new RenderTargetBitmap( pixelWidth, pixelHeight, dpiX, dpiY, PixelFormats.Pbgra32); targetBitmap.Render(drawingVisual); // Encoding the RenderBitmapTarget as an image file. bitampEncoder.Frames.Add(BitmapFrame.Create(targetBitmap)); using (FileStream stream = File.Create(outputFileName)) { bitampEncoder.Save(stream); } _imageFile = outputFileName; return(true); }
private static string GetImageFileExtention(ImageEncoderType encoderType) { switch (encoderType) { case ImageEncoderType.BmpBitmap: return ".bmp"; case ImageEncoderType.GifBitmap: return ".gif"; case ImageEncoderType.JpegBitmap: return ".jpg"; case ImageEncoderType.PngBitmap: return ".png"; case ImageEncoderType.TiffBitmap: return ".tif"; case ImageEncoderType.WmpBitmap: return ".wdp"; } return ".png"; }
private bool SaveImageFile(string fileName, string imageFileName, ImageEncoderType encoderType) { if (_drawing == null) { throw new InvalidOperationException( "There is no converted drawing for the saving operation."); } string outputExt = GetImageFileExtention(encoderType); string outputFileName = null; if (String.IsNullOrEmpty(imageFileName)) { string fileNameWithoutExt = Path.GetFileNameWithoutExtension(fileName); string workingDir = Path.GetDirectoryName(fileName); outputFileName = Path.Combine(workingDir, fileNameWithoutExt + outputExt); } else { string fileExt = Path.GetExtension(imageFileName); if (String.IsNullOrEmpty(fileExt)) { outputFileName = imageFileName + outputExt; } else if (!String.Equals(fileExt, outputExt, StringComparison.OrdinalIgnoreCase)) { outputFileName = Path.ChangeExtension(imageFileName, outputExt); } else { outputFileName = imageFileName; } } string outputFileDir = Path.GetDirectoryName(outputFileName); if (!Directory.Exists(outputFileDir)) { Directory.CreateDirectory(outputFileDir); } BitmapEncoder bitampEncoder = GetBitmapEncoder(outputExt, encoderType); // The image parameters... Rect drawingBounds = _drawing.Bounds; int pixelWidth = (int)drawingBounds.Width; int pixelHeight = (int)drawingBounds.Height; double dpiX = 96; double dpiY = 96; // The Visual to use as the source of the RenderTargetBitmap. DrawingVisual drawingVisual = new DrawingVisual(); DrawingContext drawingContext = drawingVisual.RenderOpen(); drawingContext.DrawDrawing(_drawing); drawingContext.Close(); // The BitmapSource that is rendered with a Visual. RenderTargetBitmap targetBitmap = new RenderTargetBitmap( pixelWidth, pixelHeight, dpiX, dpiY, PixelFormats.Pbgra32); targetBitmap.Render(drawingVisual); // Encoding the RenderBitmapTarget as an image file. bitampEncoder.Frames.Add(BitmapFrame.Create(targetBitmap)); using (FileStream stream = File.Create(outputFileName)) { bitampEncoder.Save(stream); } _imageFile = outputFileName; return true; }
public bool SaveImage(string fileName, FileInfo imageFileName, ImageEncoderType encoderType) { return this.SaveImageFile(fileName, imageFileName == null ? String.Empty : imageFileName.FullName, encoderType); }
/// <summary> /// Initializes a new instance of the <see cref="StreamSvgConverter"/> class /// with the specified drawing or rendering settings and the saving options. /// </summary> /// <param name="saveXaml"> /// This specifies whether to save result object tree in image file. /// </param> /// <param name="saveZaml"> /// This specifies whether to save result object tree in ZAML file. The /// ZAML is simply a G-Zip compressed image format, similar to the SVGZ. /// </param> /// <param name="settings"> /// This specifies the settings used by the rendering or drawing engine. /// If this is <see langword="null"/>, the default settings is used. /// </param> public StreamSvgConverter(bool saveXaml, bool saveZaml, WpfDrawingSettings settings) : base(saveXaml, saveZaml, settings) { _encoderType = ImageEncoderType.PngBitmap; _wpfRenderer = new WpfDrawingRenderer(this.DrawingSettings); _wpfWindow = new WpfSvgWindow(640, 480, _wpfRenderer); }
public bool SaveImage(string fileName, DirectoryInfo imageFileDir, ImageEncoderType encoderType) { if (imageFileDir == null) { return this.SaveImageFile(fileName, String.Empty, encoderType); } else { if (!imageFileDir.Exists) { imageFileDir.Create(); } string outputExt = GetImageFileExtention(encoderType); string fileNameWithoutExt = Path.GetFileNameWithoutExtension( fileName); string imageFileName = Path.Combine(imageFileDir.FullName, fileNameWithoutExt + outputExt); return this.SaveImageFile(fileName, imageFileName, encoderType); } }