public bool TryGetBitmapTransform(string optionValue, IEnumerable<KeyValuePair<string, string>> settings, out Func<BitmapSource, BitmapSource> bitmapTransformerFunc)
{
int maxWidth;
if(!int.TryParse(optionValue, out maxWidth))
{
bitmapTransformerFunc = null;
return false;
}
bitmapTransformerFunc = (sourceBitmap =>
{
if (sourceBitmap.PixelWidth <= maxWidth)
{
return sourceBitmap;
}
var scale = maxWidth / (double)sourceBitmap.PixelWidth;
return new TransformedBitmap(sourceBitmap, new ScaleTransform(scale, scale));
});
return true;
}