public Rect scalePreview(Size previewSize, Size viewfinderSize) {
        // We avoid scaling if feasible.
        Size scaledPreview = previewSize.scaleFit(viewfinderSize);
        Log.i(TAG, "Preview: " + previewSize + "; Scaled: " + scaledPreview + "; Want: " + viewfinderSize);

        int dx = (scaledPreview.width - viewfinderSize.width) / 2;
        int dy = (scaledPreview.height - viewfinderSize.height) / 2;

        return new Rect(-dx, -dy, scaledPreview.width - dx, scaledPreview.height - dy);
    }
Scale the preview to cover the viewfinder, then center it.

Aspect ratio is preserved.

@param previewSize the size of the preview (camera), in current display orientation
@param viewfinderSize the size of the viewfinder (display), in current display orientation
@return a rect placing the preview
zxing-android-embedded/src/com/journeyapps/barcodescanner/camera/FitCenterStrategy.java