Bombsquad.DynamicMedia.Imaging.BitmapTransforms.MaxHeightBitmapTransformerFactory.TryGetBitmapTransform C# (CSharp) Method

TryGetBitmapTransform() public method

public TryGetBitmapTransform ( string optionValue, string>.IEnumerable settings, BitmapSource>.Func &bitmapTransformerFunc ) : bool
optionValue string
settings string>.IEnumerable
bitmapTransformerFunc BitmapSource>.Func
return bool
        public bool TryGetBitmapTransform(string optionValue, IEnumerable<KeyValuePair<string, string>> settings, out Func<BitmapSource, BitmapSource> bitmapTransformerFunc)
        {
            int maxHeight;
            if (!int.TryParse(optionValue, out maxHeight))
            {
                bitmapTransformerFunc = null;
                return false;
            }

            bitmapTransformerFunc = (sourceBitmap =>
            {
                if (sourceBitmap.PixelHeight <= maxHeight)
                {
                    return sourceBitmap;
                }

                var scale = maxHeight / (double)sourceBitmap.PixelHeight;
                return new TransformedBitmap(sourceBitmap, new ScaleTransform(scale, scale));
            });
            return true;
        }
MaxHeightBitmapTransformerFactory