|
@@ -1,10 +1,10 @@
|
|
using System.Drawing;
|
|
using System.Drawing;
|
|
using Android.Graphics;
|
|
using Android.Graphics;
|
|
using Android.Media;
|
|
using Android.Media;
|
|
|
|
+using Avalonia.Controls;
|
|
using InABox.Core;
|
|
using InABox.Core;
|
|
using Java.IO;
|
|
using Java.IO;
|
|
using Microsoft.Maui.Media;
|
|
using Microsoft.Maui.Media;
|
|
-using Microsoft.Maui.Storage;
|
|
|
|
using Bitmap = Android.Graphics.Bitmap;
|
|
using Bitmap = Android.Graphics.Bitmap;
|
|
using File = System.IO.File;
|
|
using File = System.IO.File;
|
|
using Path = System.IO.Path;
|
|
using Path = System.IO.Path;
|
|
@@ -61,25 +61,45 @@ namespace InABox.Avalonia.Platform.Android
|
|
Rotate270 = 8
|
|
Rotate270 = 8
|
|
}
|
|
}
|
|
|
|
|
|
- public async Task<FileResult> PickPhotoAsync(int? compression, Size? constraints)
|
|
|
|
|
|
+ public async Task<ImageFile?> PickPhotoAsync(TopLevel window, int? compression, Size? constraints)
|
|
{
|
|
{
|
|
var fileResult = await MediaPicker.PickPhotoAsync();
|
|
var fileResult = await MediaPicker.PickPhotoAsync();
|
|
if (fileResult == null)
|
|
if (fileResult == null)
|
|
return null;
|
|
return null;
|
|
- return await ProcessFile(fileResult, compression, constraints);
|
|
|
|
|
|
+ await using var stream = await fileResult.OpenReadAsync();
|
|
|
|
+ return await ProcessFile(stream, compression, constraints);
|
|
}
|
|
}
|
|
|
|
|
|
- public async Task<FileResult> CapturePhotoAsync(int? compression, Size? constraints)
|
|
|
|
|
|
+ public async Task<ImageFile?> CapturePhotoAsync(TopLevel window, int? compression, Size? constraints)
|
|
{
|
|
{
|
|
var fileResult = await MediaPicker.CapturePhotoAsync();
|
|
var fileResult = await MediaPicker.CapturePhotoAsync();
|
|
if (fileResult == null)
|
|
if (fileResult == null)
|
|
return null;
|
|
return null;
|
|
- return await ProcessFile(fileResult, compression, constraints);
|
|
|
|
|
|
+ await using var stream = await fileResult.OpenReadAsync();
|
|
|
|
+ return await ProcessFile(stream, compression, constraints);
|
|
}
|
|
}
|
|
-
|
|
|
|
- private async Task<FileResult> ProcessFile(FileResult fileResult, int? compression, Size? constraints)
|
|
|
|
|
|
+
|
|
|
|
+ public async Task<ImageFile?> PickVideoAsync(TopLevel window)
|
|
|
|
+ {
|
|
|
|
+ var fileResult = await MediaPicker.PickPhotoAsync();
|
|
|
|
+ if (fileResult == null)
|
|
|
|
+ return null;
|
|
|
|
+ await using var stream = await fileResult.OpenReadAsync();
|
|
|
|
+ return await ProcessFile(stream, null, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public async Task<ImageFile?> CaptureVideoAsync(TopLevel window)
|
|
{
|
|
{
|
|
|
|
+ var fileResult = await MediaPicker.CapturePhotoAsync();
|
|
|
|
+ if (fileResult == null)
|
|
|
|
+ return null;
|
|
await using var stream = await fileResult.OpenReadAsync();
|
|
await using var stream = await fileResult.OpenReadAsync();
|
|
|
|
+ return await ProcessFile(stream, null, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private async Task<ImageFile> ProcessFile(Stream stream, int? compression, Size? constraints)
|
|
|
|
+ {
|
|
|
|
+ //await using var stream = await fileResult.OpenReadAsync();
|
|
|
|
|
|
var orientation = GetImageOrientation(stream);
|
|
var orientation = GetImageOrientation(stream);
|
|
|
|
|
|
@@ -87,8 +107,7 @@ namespace InABox.Avalonia.Platform.Android
|
|
var rotated = RotateImage(source, orientation);
|
|
var rotated = RotateImage(source, orientation);
|
|
|
|
|
|
var scaled = ScaleImage(rotated, constraints);
|
|
var scaled = ScaleImage(rotated, constraints);
|
|
-
|
|
|
|
- var jpegFilename = Path.Combine(FileSystem.CacheDirectory, $"{Guid.NewGuid()}.jpg");
|
|
|
|
|
|
+ var jpegFilename = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), $"{Guid.NewGuid()}.jpg");
|
|
using (var outStream = new MemoryStream())
|
|
using (var outStream = new MemoryStream())
|
|
{
|
|
{
|
|
await scaled.CompressAsync(Bitmap.CompressFormat.Jpeg, compression ?? 100, outStream);
|
|
await scaled.CompressAsync(Bitmap.CompressFormat.Jpeg, compression ?? 100, outStream);
|
|
@@ -96,7 +115,7 @@ namespace InABox.Avalonia.Platform.Android
|
|
await File.WriteAllBytesAsync(jpegFilename, outStream.ToArray());
|
|
await File.WriteAllBytesAsync(jpegFilename, outStream.ToArray());
|
|
}
|
|
}
|
|
|
|
|
|
- return new FileResult(jpegFilename);
|
|
|
|
|
|
+ return new ImageFile(jpegFilename);
|
|
}
|
|
}
|
|
|
|
|
|
private static Bitmap RotateImage(Bitmap source, ImageOrientation orientation)
|
|
private static Bitmap RotateImage(Bitmap source, ImageOrientation orientation)
|