diff --git a/BlazorInputFile/FileListEntryImpl.cs b/BlazorInputFile/FileListEntryImpl.cs index 314558b..0b29dde 100644 --- a/BlazorInputFile/FileListEntryImpl.cs +++ b/BlazorInputFile/FileListEntryImpl.cs @@ -35,9 +35,9 @@ public Stream Data } } - public async Task ToImageFileAsync(string format, int maxWidth, int maxHeight) + public async Task ToImageFileAsync(string format, int maxWidth, int maxHeight, float imgQuality) { - return await Owner.ConvertToImageFileAsync(this, format, maxWidth, maxHeight); + return await Owner.ConvertToImageFileAsync(this, format, maxWidth, maxHeight, imgQuality); } internal void RaiseOnDataRead() diff --git a/BlazorInputFile/IFileListEntry.cs b/BlazorInputFile/IFileListEntry.cs index 9158718..9b46a38 100644 --- a/BlazorInputFile/IFileListEntry.cs +++ b/BlazorInputFile/IFileListEntry.cs @@ -18,7 +18,7 @@ public interface IFileListEntry Stream Data { get; } - Task ToImageFileAsync(string format, int maxWidth, int maxHeight); + Task ToImageFileAsync(string format, int maxWidth, int maxHeight, float imgQuality); event EventHandler OnDataRead; } diff --git a/BlazorInputFile/InputFile.razor b/BlazorInputFile/InputFile.razor index 9cd9a76..cd38f6f 100644 --- a/BlazorInputFile/InputFile.razor +++ b/BlazorInputFile/InputFile.razor @@ -40,9 +40,9 @@ : new RemoteFileListEntryStream(JSRuntime, inputFileElement, file, MaxMessageSize, MaxBufferSize); } - internal async Task ConvertToImageFileAsync(FileListEntryImpl file, string format, int maxWidth, int maxHeight) + internal async Task ConvertToImageFileAsync(FileListEntryImpl file, string format, int maxWidth, int maxHeight, float imgQuality) { - var imageFile = await JSRuntime.InvokeAsync("BlazorInputFile.toImageFile", inputFileElement, file.Id, format, maxWidth, maxHeight); + var imageFile = await JSRuntime.InvokeAsync("BlazorInputFile.toImageFile", inputFileElement, file.Id, format, maxWidth, maxHeight, imgQuality); // So that method invocations on the file can be dispatched back here imageFile.Owner = (InputFile)(object)this; diff --git a/BlazorInputFile/wwwroot/inputfile.js b/BlazorInputFile/wwwroot/inputfile.js index bb2be20..6f6bfbe 100644 --- a/BlazorInputFile/wwwroot/inputfile.js +++ b/BlazorInputFile/wwwroot/inputfile.js @@ -34,7 +34,7 @@ }); }, - toImageFile(elem, fileId, format, maxWidth, maxHeight) { + toImageFile(elem, fileId, format, maxWidth, maxHeight, imgQuality) { var originalFile = getFileById(elem, fileId); return new Promise(function (resolve) { @@ -51,7 +51,7 @@ canvas.width = Math.round(loadedImage.width * chosenSizeRatio); canvas.height = Math.round(loadedImage.height * chosenSizeRatio); canvas.getContext('2d').drawImage(loadedImage, 0, 0, canvas.width, canvas.height); - canvas.toBlob(resolve, format); + canvas.toBlob(resolve, format, imgQuality); }); }).then(function (resizedImageBlob) { var result = {