Private Sub GetOptimal As CameraSize
Dim last_sizes As CameraSize
last_sizes.Initialize(0,0)
For Each prev_sizes As CameraSize In cam.SupportedPreviewSizes
If prev_sizes.Height <= xpnl_camera_background.Width And prev_sizes.Width <= xpnl_camera_background.Height And prev_sizes.Height >= last_sizes.Height And prev_sizes.Width >= last_sizes.Width Then
last_sizes.Initialize(prev_sizes.Width,prev_sizes.Height)
Return last_sizes
End If
Next
Return last_sizes
End Sub
Sub PrepareSurface As ResumableSub
Dim last_sizes As CameraSize = GetOptimal
xpnl_camera_background.SetLayoutAnimated(0,(Root.Width - last_sizes.Height)/2,(Root.Height - last_sizes.Width)/2,last_sizes.Height,last_sizes.Width)
cam.PreviewSize.Initialize(last_sizes.Width,last_sizes.Height)
Wait For (cam.PrepareSurface(MyTaskIndex)) Complete (Success As Boolean)
If Success Then cam.StartPreview(MyTaskIndex, False)
Return Success
End Sub