Search code examples
c#xamarinxamarin.formsxamarin.android

Put an image from camera with migradoc or pdfsharp with xamarin forms


I have a problem that I can't put an image from the camera to the pdf. It put the same error "Image could not read". How can I do it? This is the path they gave me when I take a photo =

"/storage/emulated/0/Android/data/com.companyname.atecresacalculator/files/Pictures/fotoparapdf_12.jpg"

code from CompartirInformacion(SharedInformation):

namespace AtecresaCalculator.Service
{
    public class CompartirInformacion
    {
        public static string x;
        public static string y;
    }   
}

where I added into the pdf:

Row row = table.AddRow();
table.Rows.HeightRule = RowHeightRule.Auto;
row.Cells[0].AddParagraph(text);
row.Cells[0].VerticalAlignment = VerticalAlignment.Center;
row.Cells[1].AddParagraph(texto);
row.Cells[1].AddImage(FromFile(CompartirInformacion.y));
row.Cells[1].VerticalAlignment = VerticalAlignment.Center;

Clicked to take the photo:

private async void sacarFoto_Clicked(object sender, EventArgs e)
{
    await CrossMedia.Current.Initialize();
    if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
    {
        await DisplayAlert("Error en la cámara", "Activa los permisos para usar cámara", "Ok");
        return;
    }

    var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
    {
        PhotoSize = Plugin.Media.Abstractions.PhotoSize.Small,
        Name = "fotoparapdf.jpg",
        CompressionQuality = 100,
        DefaultCamera = Plugin.Media.Abstractions.CameraDevice.Rear,
    });

    if (file == null)
        return;

    await DisplayAlert("Ruta de la foto", file.Path, "Ok");

    CompartirInformacion.y = file.Path;
}

Solution

  • Currently you can not do what you ask with this package. if you need to do that you should try with the Syncfusion pdf package, the bad thing is that it is paid but you can create a community account for free