.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.MAUI.Pages.Media;
|
||||
using WorkFlowCheck.MAUI.Services.Interfaces;
|
||||
namespace WorkFlowCheck.MAUI
|
||||
{
|
||||
@@ -29,20 +30,21 @@ namespace WorkFlowCheck.MAUI
|
||||
}
|
||||
private async void OnButtonGetUser(object sender, EventArgs e)
|
||||
{
|
||||
var response = await _userService.GetUserAsync();
|
||||
if (response != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
WelcomeLabel.Text = response.Data.FirstName;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//var response = await _userService.GetUserAsync();
|
||||
//if (response != null)
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// WelcomeLabel.Text = response.Data.FirstName;
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
|
||||
WelcomeLabel.Text = ex.Message;
|
||||
}
|
||||
// WelcomeLabel.Text = ex.Message;
|
||||
// }
|
||||
|
||||
}
|
||||
//}
|
||||
await Navigation.PushAsync(new CaptureImagePage());
|
||||
}
|
||||
private async void OnButtonNFCTest(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
@@ -52,6 +52,7 @@ namespace WorkFlowCheck.MAUI
|
||||
|
||||
builder.UseMauiApp<App>()
|
||||
.UseDevExpressEditors()
|
||||
.UseMauiCommunityToolkitCamera()
|
||||
.ConfigureFonts(fonts =>
|
||||
{
|
||||
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
|
||||
|
||||
@@ -4,75 +4,16 @@
|
||||
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>
|
||||
<!-- Gomb a kép készítéséhez -->
|
||||
<Button Text="Kép készítése"
|
||||
Clicked="OnCaptureClicked" />
|
||||
|
||||
<!-- Kép megjelenítése -->
|
||||
<Frame BorderColor="Gray" Padding="10" Margin="5" HasShadow="True">
|
||||
<Image x:Name="CapturedImage"
|
||||
HeightRequest="200"
|
||||
Aspect="AspectFit" />
|
||||
</Frame>
|
||||
</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>
|
||||
@@ -1,7 +1,9 @@
|
||||
using CommunityToolkit.Maui.Views;
|
||||
using Microsoft.Maui.Controls;
|
||||
using System;
|
||||
using Microsoft.Maui.Storage;
|
||||
|
||||
namespace WorkFlowCheck.MAUI.Pages.Media;
|
||||
using Microsoft.Maui.Media;
|
||||
|
||||
|
||||
public partial class CaptureImagePage : ContentPage
|
||||
{
|
||||
public CaptureImagePage()
|
||||
@@ -9,32 +11,45 @@ public partial class CaptureImagePage : ContentPage
|
||||
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();
|
||||
|
||||
if (photo != null)
|
||||
// Ellenőrizzük, hogy a MediaPicker elérhető-e az eszközön
|
||||
if (MediaPicker.IsCaptureSupported)
|
||||
{
|
||||
// A kép elérési útja
|
||||
string localFilePath = Path.Combine(FileSystem.CacheDirectory, photo.FileName);
|
||||
// Kép készítése
|
||||
var photo = await MediaPicker.CapturePhotoAsync();
|
||||
|
||||
// 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);
|
||||
// A kép mentése a fájlrendszerbe
|
||||
var filePath = Path.Combine(FileSystem.CacheDirectory, "captured_photo.jpg");
|
||||
|
||||
// Esetleg megjelenítheted az UI-ban
|
||||
PhotoPath = localFilePath;
|
||||
// A kép átmásolása a kívánt helyre
|
||||
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
|
||||
{
|
||||
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>
|
||||
<PackageReference Include="AutoMapper" Version="13.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="DevExpress.Maui.Controls" Version="24.1.10" />
|
||||
<PackageReference Include="DevExpress.Maui.Core" Version="24.1.10" />
|
||||
|
||||
Reference in New Issue
Block a user