Kamera használatához alapok

This commit is contained in:
Iván Szabó
2025-02-24 13:39:05 +01:00
parent f3ef12ccc4
commit 5396fc0dcb
7 changed files with 151 additions and 5 deletions
@@ -0,0 +1,40 @@
namespace WorkFlowCheck.MAUI.Pages.Media;
using Microsoft.Maui.Media;
public partial class CaptureImagePage : ContentPage
{
public CaptureImagePage()
{
InitializeComponent();
}
public string PhotoPath { get; private set; }
private async Task TakePhotoAsync()
{
if (MediaPicker.Default.IsCaptureSupported)
{
FileResult photo = await MediaPicker.Default.CapturePhotoAsync();
if (photo != null)
{
// A kép elérési útja
string localFilePath = Path.Combine(FileSystem.CacheDirectory, photo.FileName);
// A kép mentése a helyi fájlrendszerbe
using Stream sourceStream = await photo.OpenReadAsync();
using FileStream localFileStream = File.OpenWrite(localFilePath);
await sourceStream.CopyToAsync(localFileStream);
// Esetleg megjelenítheted az UI-ban
PhotoPath = localFilePath;
}
}
else
{
await Application.Current.MainPage.DisplayAlert("Hiba", "A kamerához való hozzáférés nem támogatott.", "OK");
}
}
}