protected async Task ConvertImageAsync(string source, string destination, int widthDp, int heightDp, int dpi, ImageFormat extension, ColorInfo color) { var pixelWidth = ResolutionConverter.DpToPixel(widthDp, dpi); var pixelHeight = ResolutionConverter.DpToPixel(heightDp, dpi); using (var bitmap = new Bitmap(pixelWidth, pixelHeight)) { var document = SvgDocument.Open(source); document.Width = new SvgUnit(SvgUnitType.Pixel, pixelWidth); document.Height = new SvgUnit(SvgUnitType.Pixel, pixelHeight); document.Ppi = dpi; if (color != null) { foreach (var documentChild in document.Children) { ChangeFill(document, documentChild, ColorHelper.FromRgb(color.HexCode)); } } document.Draw(bitmap); using (var writeStream = new FileStream(destination, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) { bitmap.Save(writeStream, extension); } } }
public Boolean Validate(IMediaFeature feature, IRenderDevice device) { var res = ResolutionConverter.Convert(feature.Value); if (res != null) { var desired = res.AsInt32(); var available = device.Resolution; if (feature.IsMaximum) { return(available <= desired); } else if (feature.IsMinimum) { return(available >= desired); } return(desired == available); } return(false); }