Pregunta

I have both a CameraCaptureTask and a PhotoChooserTask in my app where you can either take or load a photo. The end goal of all of this is to finally send it to an Azure Web API.

The photo that I get back from both of these tasks is very large (about 4mb) and about 3000x2000 pixels in dimensions.

Is there a way to get a much smaller version of the picture? This is how I handle the chooser;

    public void PhotoChooserTaskCompleted(object sender, PhotoResult e)
    {
        if (e.TaskResult == TaskResult.OK)
        {
            var bmp = new BitmapImage();
            bmp.SetSource(e.ChosenPhoto);

            var writeableBitmap = new WriteableBitmap(bmp);
            ...

Is there a way to load a smaller 'thumbnail' version or do I have to manipulate the image and resize it?

Thanks for any pointers.

¿Fue útil?

Solución

WriteableBitmap bmpWritable = new WriteableBitmap(bmp);
MemoryStream ms = new MemoryStream();
Extensions.SaveJpeg(bmpWritable, ms, newWidth, newHeight, 0, 100);

I would suggest you resize it proportionally. Hope this helps.

And also, You need not to have two separate tasks for taking image from Camera and from gallery. For PhotoChooserTask itself, you can set ShowCamera attribute to true. This will display a camera button when in ApplicationBar when you open gallery

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top