You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
933 B

using System;
using Microsoft.Maui.Graphics.Platform;
namespace LolApp.ViewModels
{
public static class PickIconsAndImagesUtils
{
public async static Task<string> PickPhoto(float maxWidthAndHeight)
{
FileResult photo = await MediaPicker.Default.PickPhotoAsync();
return photo != null ? await ToBase64(photo, maxWidthAndHeight) : null;
}
public async static Task<string> ToBase64(FileResult photo, float maxWidthAndHeight)
{
using (var stream = await photo.OpenReadAsync())
using (var memoryStream = new MemoryStream())
{
var image = PlatformImage.FromStream(stream);
if(image != null)
{
var newImage = image.Downsize(maxWidthAndHeight, true);
return newImage.AsBase64();
}
}
return null;
}
}
}