Skip to content
This repository has been archived by the owner on May 5, 2021. It is now read-only.

To image file quality #50

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions BlazorInputFile/FileListEntryImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public Stream Data
}
}

public async Task<IFileListEntry> ToImageFileAsync(string format, int maxWidth, int maxHeight)
public async Task<IFileListEntry> 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()
Expand Down
2 changes: 1 addition & 1 deletion BlazorInputFile/IFileListEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface IFileListEntry

Stream Data { get; }

Task<IFileListEntry> ToImageFileAsync(string format, int maxWidth, int maxHeight);
Task<IFileListEntry> ToImageFileAsync(string format, int maxWidth, int maxHeight, float imgQuality);

event EventHandler OnDataRead;
}
Expand Down
4 changes: 2 additions & 2 deletions BlazorInputFile/InputFile.razor
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
: new RemoteFileListEntryStream(JSRuntime, inputFileElement, file, MaxMessageSize, MaxBufferSize);
}

internal async Task<FileListEntryImpl> ConvertToImageFileAsync(FileListEntryImpl file, string format, int maxWidth, int maxHeight)
internal async Task<FileListEntryImpl> ConvertToImageFileAsync(FileListEntryImpl file, string format, int maxWidth, int maxHeight, float imgQuality)
{
var imageFile = await JSRuntime.InvokeAsync<FileListEntryImpl>("BlazorInputFile.toImageFile", inputFileElement, file.Id, format, maxWidth, maxHeight);
var imageFile = await JSRuntime.InvokeAsync<FileListEntryImpl>("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;
Expand Down
4 changes: 2 additions & 2 deletions BlazorInputFile/wwwroot/inputfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 = {
Expand Down