scaleToFit method
Returns the scale required to fit the image into the given
height
and width
in pixels.
The scale is the lower of the vertical or horizontal scale. For example if the image pixelHeightxpixelWidth is 1000 x 2000 and this was called with 100x250 then the correct scale would be 10% or 0.1 since 100/1000 = 0.1 while 250/2000 = 0.125, so the the 0.1 scale is the lower of the two. Use this with DeviceImage to find a scale for a particular desired screen resolution.
Implementation
double scaleToFit(int height, int width) {
double vScale = height / pixelHeight!;
double hScale = width / pixelWidth!;
if (vScale >= 1 && hScale >= 1) {
return 1.0;
}
return min(vScale, hScale);
}