.NET 8 LTS-ben MediaPicker-rel kép készítése
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using WorkFlowCheck.Common.DTO;
|
using WorkFlowCheck.Common.DTO;
|
||||||
|
using WorkFlowCheck.MAUI.Pages.Media;
|
||||||
using WorkFlowCheck.MAUI.Services.Interfaces;
|
using WorkFlowCheck.MAUI.Services.Interfaces;
|
||||||
namespace WorkFlowCheck.MAUI
|
namespace WorkFlowCheck.MAUI
|
||||||
{
|
{
|
||||||
@@ -29,20 +30,21 @@ namespace WorkFlowCheck.MAUI
|
|||||||
}
|
}
|
||||||
private async void OnButtonGetUser(object sender, EventArgs e)
|
private async void OnButtonGetUser(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var response = await _userService.GetUserAsync();
|
//var response = await _userService.GetUserAsync();
|
||||||
if (response != null)
|
//if (response != null)
|
||||||
{
|
//{
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
WelcomeLabel.Text = response.Data.FirstName;
|
// WelcomeLabel.Text = response.Data.FirstName;
|
||||||
}
|
// }
|
||||||
catch (Exception ex)
|
// catch (Exception ex)
|
||||||
{
|
// {
|
||||||
|
|
||||||
WelcomeLabel.Text = ex.Message;
|
// WelcomeLabel.Text = ex.Message;
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
//}
|
||||||
|
await Navigation.PushAsync(new CaptureImagePage());
|
||||||
}
|
}
|
||||||
private async void OnButtonNFCTest(object sender, EventArgs e)
|
private async void OnButtonNFCTest(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ namespace WorkFlowCheck.MAUI
|
|||||||
|
|
||||||
builder.UseMauiApp<App>()
|
builder.UseMauiApp<App>()
|
||||||
.UseDevExpressEditors()
|
.UseDevExpressEditors()
|
||||||
|
.UseMauiCommunityToolkitCamera()
|
||||||
.ConfigureFonts(fonts =>
|
.ConfigureFonts(fonts =>
|
||||||
{
|
{
|
||||||
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
|
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
|
||||||
|
|||||||
@@ -4,75 +4,16 @@
|
|||||||
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
|
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
|
||||||
x:Class="WorkFlowCheck.MAUI.Pages.Media.CaptureImagePage"
|
x:Class="WorkFlowCheck.MAUI.Pages.Media.CaptureImagePage"
|
||||||
Title="CaptureImagePage">
|
Title="CaptureImagePage">
|
||||||
<Grid RowDefinitions="200,*,Auto,Auto" ColumnDefinitions="3*,*">
|
<VerticalStackLayout>
|
||||||
<toolkit:CameraView
|
<!-- Gomb a kép készítéséhez -->
|
||||||
x:Name="Camera"
|
<Button Text="Kép készítése"
|
||||||
Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" Grid.RowSpan="3"
|
Clicked="OnCaptureClicked" />
|
||||||
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"/>
|
|
||||||
|
|
||||||
|
<!-- Kép megjelenítése -->
|
||||||
|
<Frame BorderColor="Gray" Padding="10" Margin="5" HasShadow="True">
|
||||||
|
<Image x:Name="CapturedImage"
|
||||||
|
HeightRequest="200"
|
||||||
|
Aspect="AspectFit" />
|
||||||
|
</Frame>
|
||||||
</VerticalStackLayout>
|
</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>
|
</ContentPage>
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
|
using CommunityToolkit.Maui.Views;
|
||||||
|
using Microsoft.Maui.Controls;
|
||||||
|
using System;
|
||||||
|
using Microsoft.Maui.Storage;
|
||||||
|
|
||||||
namespace WorkFlowCheck.MAUI.Pages.Media;
|
namespace WorkFlowCheck.MAUI.Pages.Media;
|
||||||
using Microsoft.Maui.Media;
|
|
||||||
|
|
||||||
|
|
||||||
public partial class CaptureImagePage : ContentPage
|
public partial class CaptureImagePage : ContentPage
|
||||||
{
|
{
|
||||||
public CaptureImagePage()
|
public CaptureImagePage()
|
||||||
@@ -9,32 +11,45 @@ public partial class CaptureImagePage : ContentPage
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string PhotoPath { get; private set; }
|
|
||||||
|
|
||||||
private async Task TakePhotoAsync()
|
|
||||||
|
private async void OnCaptureClicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (MediaPicker.Default.IsCaptureSupported)
|
try
|
||||||
{
|
{
|
||||||
FileResult photo = await MediaPicker.Default.CapturePhotoAsync();
|
// Ellenőrizzük, hogy a MediaPicker elérhető-e az eszközön
|
||||||
|
if (MediaPicker.IsCaptureSupported)
|
||||||
if (photo != null)
|
|
||||||
{
|
{
|
||||||
// A kép elérési útja
|
// Kép készítése
|
||||||
string localFilePath = Path.Combine(FileSystem.CacheDirectory, photo.FileName);
|
var photo = await MediaPicker.CapturePhotoAsync();
|
||||||
|
|
||||||
// A kép mentése a helyi fájlrendszerbe
|
// A kép mentése a fájlrendszerbe
|
||||||
using Stream sourceStream = await photo.OpenReadAsync();
|
var filePath = Path.Combine(FileSystem.CacheDirectory, "captured_photo.jpg");
|
||||||
using FileStream localFileStream = File.OpenWrite(localFilePath);
|
|
||||||
await sourceStream.CopyToAsync(localFileStream);
|
|
||||||
|
|
||||||
// Esetleg megjelenítheted az UI-ban
|
// A kép átmásolása a kívánt helyre
|
||||||
PhotoPath = localFilePath;
|
using (var stream = await photo.OpenReadAsync())
|
||||||
|
using (var fileStream = File.OpenWrite(filePath))
|
||||||
|
{
|
||||||
|
await stream.CopyToAsync(fileStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A kép megjelenítése
|
||||||
|
CapturedImage.Source = ImageSource.FromFile(filePath);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await Application.Current.MainPage.DisplayAlert("Hiba", "A kamerához való hozzáférés nem támogatott.", "OK");
|
// Ha a MediaPicker nem elérhető, hibaüzenet
|
||||||
|
Console.WriteLine("A fényképezés nem támogatott ezen az eszközön.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
// Hiba kezelése
|
||||||
|
Console.WriteLine($"Hiba történt a fényképezés közben: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -59,6 +59,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AutoMapper" Version="13.0.1" />
|
<PackageReference Include="AutoMapper" Version="13.0.1" />
|
||||||
<PackageReference Include="CommunityToolkit.Maui" Version="8.0.1" />
|
<PackageReference Include="CommunityToolkit.Maui" Version="8.0.1" />
|
||||||
|
<PackageReference Include="CommunityToolkit.Maui.Camera" Version="1.0.5" />
|
||||||
<PackageReference Include="CommunityToolkit.Maui.Core" 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.Controls" Version="24.1.10" />
|
||||||
<PackageReference Include="DevExpress.Maui.Core" Version="24.1.10" />
|
<PackageReference Include="DevExpress.Maui.Core" Version="24.1.10" />
|
||||||
|
|||||||
Reference in New Issue
Block a user