From 0878071bbf27754584e9be80d5d44aff0406751d Mon Sep 17 00:00:00 2001 From: ShockwaverReal <47000778+ShockwaverReal@users.noreply.github.com> Date: Sat, 25 Jul 2020 17:04:28 +0200 Subject: [PATCH 1/4] Update IFileListEntry.cs Added parameter imgQuality to ToImageFileAsync interface function signature --- BlazorInputFile/IFileListEntry.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; } From 38e0fa24a58ea880df987c31e54668a436b899cd Mon Sep 17 00:00:00 2001 From: ShockwaverReal <47000778+ShockwaverReal@users.noreply.github.com> Date: Sat, 25 Jul 2020 17:06:04 +0200 Subject: [PATCH 2/4] Update FileListEntryImpl.cs Added imgQuality parameter to function ToImageFileAsync --- BlazorInputFile/FileListEntryImpl.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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() From 13844add2837b836d6586cab258cbb86ebdae09d Mon Sep 17 00:00:00 2001 From: ShockwaverReal <47000778+ShockwaverReal@users.noreply.github.com> Date: Sat, 25 Jul 2020 17:08:10 +0200 Subject: [PATCH 3/4] Update InputFile.razor Added imgQuality parameter to ConvertToImageFileAsync function --- BlazorInputFile/InputFile.razor | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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; From 1473aa98cb9c8a569549364e75817610b7ffcbb4 Mon Sep 17 00:00:00 2001 From: ShockwaverReal <47000778+ShockwaverReal@users.noreply.github.com> Date: Sat, 25 Jul 2020 17:09:50 +0200 Subject: [PATCH 4/4] Update inputfile.js Added imgQuality to toImageFile function --- BlazorInputFile/wwwroot/inputfile.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 = {