I'm using this code to capture an image using the mobile camera, display it and store it on the device then after clicking another button the text in the captured image will be extracted in label named TextView
public partial class MainPage : ContentPage
{
private MediaFile photo;
private string photopath;
public MainPage()
{
InitializeComponent();
}
private async void CameraButton_Clicked(object sender, EventArgs e)
{
var cameraMediaOptions = new StoreCameraMediaOptions
{
DefaultCamera = CameraDevice.Rear,
SaveToAlbum = true,
Directory = "MyAppName",
Name = null,
CompressionQuality = 100
};
photo = await CrossMedia.Current.TakePhotoAsync(cameraMediaOptions);
if (photo == null) return;
PhotoImage.Source = ImageSource.FromStream(() => photo.GetStream());
}
private async void TextButton_Clicked(object sender, EventArgs e)
{
if (photo != null)
{
var ocr = new IronTesseract();
var result = await ocr.ReadAsync(photopath);
TextView.Text = result.Text;
if (string.IsNullOrWhiteSpace(result.Text))
{
TextView.Text = "No Text Found";
return;
}
}
else
{
await DisplayAlert("Please Take Photo First", "", "OK");
return;
}
}
}
what happend is after running the app i click on text extraction button befor capturing photo and the alert displays "Please Take Photo First appear", then capturing the photo and display it and everything is fine, but after capturing the image when in click the text extraction button suddenly the app break and no enough information is displayed, tried to use chatGPT to check the problem since I am begginer and it said that it might be in the way I defiend the image path and feeding it to the IronOcr library, please help me here is pic of the break mode message : enter image description here