Kamera használatához alapok
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="WorkFlowCheck.MAUI.Pages.CheckList.CheckListPage"
|
||||
Title="CheckListPage">
|
||||
<VerticalStackLayout>
|
||||
<Label
|
||||
Text="Welcome to .NET MAUI!"
|
||||
VerticalOptions="Center"
|
||||
HorizontalOptions="Center" />
|
||||
</VerticalStackLayout>
|
||||
</ContentPage>
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace WorkFlowCheck.MAUI.Pages.CheckList;
|
||||
|
||||
public partial class CheckListPage : ContentPage
|
||||
{
|
||||
public CheckListPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
|
||||
x:Class="WorkFlowCheck.MAUI.Pages.Media.CaptureImagePage"
|
||||
Title="CaptureImagePage">
|
||||
<Grid RowDefinitions="200,*,Auto,Auto" ColumnDefinitions="3*,*">
|
||||
<toolkit:CameraView
|
||||
x:Name="Camera"
|
||||
Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" Grid.RowSpan="3"
|
||||
CameraFlashMode="{Binding FlashMode}"
|
||||
ZoomFactor="{Binding CurrentZoom}"
|
||||
ImageCaptureResolution="{Binding SelectedResolution}"
|
||||
SelectedCamera="{Binding SelectedCamera}"/>
|
||||
|
||||
<Grid Grid.Column="0" Grid.Row="0" RowDefinitions="Auto" BackgroundColor="#80CCCCCC">
|
||||
|
||||
<VerticalStackLayout Spacing="5" Padding="5" >
|
||||
<Label Text="{Binding CameraNameText}" />
|
||||
<Label Text="{Binding FlashModeText}" />
|
||||
<Label Text="{Binding ZoomRangeText}" />
|
||||
<Label Text="{Binding CurrentZoomText}" />
|
||||
<Label Text="{Binding ResolutionText}" />
|
||||
<Picker
|
||||
Title="Available Resolutions"
|
||||
ItemsSource="{Binding SelectedCamera.SupportedResolutions, FallbackValue=''}"
|
||||
SelectedItem="{Binding SelectedResolution}" />
|
||||
<Label x:Name="debugText"/>
|
||||
|
||||
</VerticalStackLayout>
|
||||
</Grid>
|
||||
|
||||
<ContentView Grid.Column="1" Grid.Row="0" ZIndex="100" BackgroundColor="#80CCCCCC">
|
||||
<Image x:Name="image" VerticalOptions="Fill" HorizontalOptions="Fill">
|
||||
<Image.GestureRecognizers>
|
||||
<TapGestureRecognizer Tapped="OnImageTapped" />
|
||||
</Image.GestureRecognizers>
|
||||
</Image>
|
||||
</ContentView>
|
||||
|
||||
<Grid ColumnDefinitions="Auto,*,Auto" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="2" ColumnSpacing="10" Margin="10"
|
||||
BackgroundColor="#00000000">
|
||||
<Button Clicked="ZoomOut" Text="Zoom -" Grid.Column="0"/>
|
||||
|
||||
<Slider
|
||||
x:Name="slider" Grid.Column="1"
|
||||
Value="{Binding CurrentZoom}"
|
||||
Maximum="{Binding SelectedCamera.MaximumZoomFactor, FallbackValue=1}"
|
||||
Minimum="{Binding SelectedCamera.MinimumZoomFactor, FallbackValue=1}"/>
|
||||
|
||||
<Button Clicked="ZoomIn" Text="Zoom +" Grid.Column="2"/>
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="3" BackgroundColor="#80CCCCCC">
|
||||
|
||||
<FlexLayout Margin="5" JustifyContent="SpaceBetween" Wrap="Wrap">
|
||||
|
||||
<Picker
|
||||
Title="Flash"
|
||||
IsVisible="{Binding Path=SelectedCamera.IsFlashSupported, FallbackValue=false}"
|
||||
ItemsSource="{Binding FlashModes}"
|
||||
SelectedItem="{Binding FlashMode}" />
|
||||
|
||||
<Button Command="{Binding CaptureImageCommand, Source={x:Reference Camera}, x:DataType=toolkit:CameraView}"
|
||||
CommandParameter="{Binding Token}"
|
||||
Text="Capture Image"/>
|
||||
<Button Command="{Binding StartCameraPreviewCommand, Source={x:Reference Camera}, x:DataType=toolkit:CameraView}"
|
||||
CommandParameter="{Binding Token}"
|
||||
Text="StartCameraPreview" />
|
||||
|
||||
<Button Command="{Binding StopCameraPreviewCommand, Source={x:Reference Camera}, x:DataType=toolkit:CameraView}"
|
||||
Text="StopCameraPreview" />
|
||||
|
||||
</FlexLayout>
|
||||
</Grid>
|
||||
|
||||
</Grid>
|
||||
</ContentPage>
|
||||
@@ -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