Kamera használatához alapok
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user