This repository has been archived by the owner on May 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support conversion/resizing of image files
- Loading branch information
1 parent
ef155e5
commit db43dc1
Showing
6 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
@page "/image" | ||
|
||
<h1>Image file</h1> | ||
|
||
<p>A single file input that reads the input as an image in a chosen format with specified maximum dimensions.</p> | ||
|
||
<InputFile OnChange="HandleSelection" /> | ||
|
||
<p>@status</p> | ||
|
||
@if (!string.IsNullOrEmpty(imageDataUri)) | ||
{ | ||
<img src="@imageDataUri" /> | ||
} | ||
|
||
@code { | ||
string status; | ||
string imageDataUri; | ||
|
||
async Task HandleSelection(IFileListEntry[] files) | ||
{ | ||
var rawFile = files.FirstOrDefault(); | ||
if (rawFile != null) | ||
{ | ||
// Load as an image file in memory | ||
var format = "image/jpeg"; | ||
var imageFile = await rawFile.ToImageFileAsync(format, 640, 480); | ||
var ms = new MemoryStream(); | ||
await imageFile.Data.CopyToAsync(ms); | ||
|
||
// Make a data URL so we can display it | ||
imageDataUri = $"data:{format};base64,{Convert.ToBase64String(ms.ToArray())}"; | ||
|
||
status = $"Finished loading {ms.Length} bytes from {imageFile.Name}"; | ||
} | ||
} | ||
} |