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
+4 -1
View File
@@ -10,6 +10,7 @@ using WorkFlowCheck.MAUI.Services.Interfaces;
using DevExpress.Maui;
using Microsoft.Maui.Controls.Hosting;
using Microsoft.Maui.Hosting;
using CommunityToolkit.Maui.Core;
namespace WorkFlowCheck.MAUI
{
@@ -55,7 +56,9 @@ namespace WorkFlowCheck.MAUI
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
}).UseMauiCommunityToolkit();
})
.UseMauiCommunityToolkitCore()
.UseMauiCommunityToolkit();
#if DEBUG
builder.Logging.AddDebug();
#endif
@@ -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");
}
}
}
@@ -7,6 +7,7 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.nfc" android:required="false" />
@@ -59,6 +59,7 @@
<ItemGroup>
<PackageReference Include="AutoMapper" Version="13.0.1" />
<PackageReference Include="CommunityToolkit.Maui" Version="8.0.1" />
<PackageReference Include="CommunityToolkit.Maui.Core" Version="8.0.1" />
<PackageReference Include="DevExpress.Maui.Controls" Version="24.1.10" />
<PackageReference Include="DevExpress.Maui.Core" Version="24.1.10" />
<PackageReference Include="DevExpress.Maui.Editors" Version="24.1.10" />
@@ -103,6 +104,12 @@
<MauiXaml Update="Pages\BaseStock\Locations\LocationsPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Pages\CheckList\CheckListPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Pages\Media\CaptureImagePage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Pages\NFC\NFCTestPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
@@ -114,8 +121,4 @@
</MauiXaml>
</ItemGroup>
<ItemGroup>
<Folder Include="Pages\CheckList\" />
</ItemGroup>
</Project>