Closed
Description
Is your feature request related to a problem? Please describe.
Need to upload file and resize it if it is too large.
Using RequestImageFileAsync
omit files with dimensions less than given parameters.
The issue is that height and width of an image are inaccessible directly from blazor.
Describe the solution you'd like
InputImage could inherit from InputFile
<InputImage id="fileInput" OnChange="UploadFile" hidden />
string PhotoPath ="";
async Task UploadFile(InputFileChangeEventArgs e)
{
var file = e.File;
var resizedImage= await file.RequestImageFileAsync(imageType, 200, 200);
if(resizedImage.Height>file.Height || resizedImage.Width>file.Width)
{
var buffer = new byte[file.Size];
await resizedImage.OpenReadStream().ReadAsync(buffer);
PhotoPath = $"data:{imageType};base64,{Convert.ToBase64String(buffer)}";
StateHasChanged();
}else
{
var buffer = new byte[resizedImage.Size];
await resizedImage.OpenReadStream().ReadAsync(buffer);
PhotoPath = $"data:{imageType};base64,{Convert.ToBase64String(buffer)}";
StateHasChanged();
}
}