fix(image): image aspect dimensions for ImageSource.fromAsset(...) (#5556)

This commit is contained in:
Manol Donev
2018-03-19 17:01:26 +02:00
committed by GitHub
parent c02bb283a9
commit 7506905770
2 changed files with 3 additions and 4 deletions

View File

@@ -141,8 +141,8 @@ export function testFromAssetWithScalingAndAspectRatio(done) {
}; };
let img = imageSource.fromAsset(asset).then((source) => { let img = imageSource.fromAsset(asset).then((source) => {
TKUnit.assertEqual(source.width, scaleWidth); TKUnit.assertEqual(source.width, 18);
TKUnit.assertEqual(source.height, 5); TKUnit.assertEqual(source.height, scaleHeight);
done(); done();
}, (error) => { }, (error) => {
done(error); done(error);

View File

@@ -33,8 +33,7 @@ export class ImageAsset extends observable.Observable implements definition.Ima
export function getAspectSafeDimensions(sourceWidth, sourceHeight, reqWidth, reqHeight) { export function getAspectSafeDimensions(sourceWidth, sourceHeight, reqWidth, reqHeight) {
let widthCoef = sourceWidth / reqWidth; let widthCoef = sourceWidth / reqWidth;
let heightCoef = sourceHeight / reqHeight; let heightCoef = sourceHeight / reqHeight;
let aspectCoef = Math.min(widthCoef, heightCoef);
let aspectCoef = widthCoef > heightCoef ? widthCoef : heightCoef;
return { return {
width: Math.floor(sourceWidth / aspectCoef), width: Math.floor(sourceWidth / aspectCoef),