public class PreviewViewMeteringPointFactory
Implement the MeteringPointFactory for PreviewView by DisplayOrientedMeteringPointFactory.
The width / height in DisplayOrientedMeteringPointFactory defines area (0, 0) - (width, height) which represents the full preview surface. The (x, y) passed to createPoint() must be in this coordinate system.
However, in PreviewView, the preview could be cropped or letterbox/pillarbox depending on the scaleType. Thus we need to adjust two things for DisplayOrientedMeteringPointFactory. (1) Calculate the new width/height of factory based on the FIT/FULL scaleType to make it represent the full preview (2) Add offset to the (x, y) in convertPoint based on the BEGIN/CENTER/END scaleType.
public PreviewViewMeteringPointFactory(@NotNull
android.view.Display display,
@NotNull
androidx.camera.core.CameraInfo cameraInfo,
@Nullable
android.util.Size resolution,
@NotNull
androidx.camera.view.PreviewView.ScaleType scaleType,
int viewWidth,
int viewHeight)
Implement the MeteringPointFactory for PreviewView by DisplayOrientedMeteringPointFactory.
The width / height in DisplayOrientedMeteringPointFactory defines area (0, 0) - (width, height) which represents the full preview surface. The (x, y) passed to createPoint() must be in this coordinate system.
However, in PreviewView, the preview could be cropped or letterbox/pillarbox depending on the scaleType. Thus we need to adjust two things for DisplayOrientedMeteringPointFactory. (1) Calculate the new width/height of factory based on the FIT/FULL scaleType to make it represent the full preview (2) Add offset to the (x, y) in convertPoint based on the BEGIN/CENTER/END scaleType.