MOBILE BugFix

This commit is contained in:
2025-06-29 13:30:34 +02:00
parent e5dd9aad27
commit d42900e8f6
4 changed files with 29 additions and 31 deletions
@@ -137,7 +137,7 @@
Source="{Binding Photo, Converter={StaticResource ByteArrayToImageSourceConverter}}" />
<Button Text="📷" Grid.Column="1"
VerticalOptions="Center"
Command="{Binding BindingContext.CreatePhoto, Source={x:Reference CheckPointCheckListRows}}"
Command="{Binding BindingContext.TakePhoto, Source={x:Reference CheckPointCheckListRows}}"
CommandParameter="{Binding .}" />
</Grid>
</Grid>
@@ -30,7 +30,7 @@ public partial class CheckListWorkPage : ContentPage
}
}
public ObservableCollection<CheckListRowDTO> CheckListRows { get; set; } = new ObservableCollection<CheckListRowDTO>();
public ICommand CreatePhoto { get; set; }
public ICommand TakePhoto { get; set; }
public ICommand SendCommand { get; set; }
public ICommand SaveCommand { get; set; }
@@ -95,7 +95,7 @@ public partial class CheckListWorkPage : ContentPage
progressLabel.Text = "Szinkronizálás befejezve!";
await Shell.Current.GoToAsync("//CheckListPage");
}
catch (Exception ex)
{
@@ -146,42 +146,40 @@ public partial class CheckListWorkPage : ContentPage
base.OnAppearing();
BindingContext = this;
await SetInfo();
CreatePhoto = new Command<CheckListRowDTO>(OnTakePhoto);
TakePhoto = new Command<CheckListRowDTO>(OnTakePhoto);
await LoadCheckPointCheckListRows();
}
private async Task<byte[]> ResizePicture(FileResult? photo, int newWidth)
{
using var stream = await photo.OpenReadAsync();
using var originalBitmap = SKBitmap.Decode(stream);
int newHeight = (int)(originalBitmap.Height * ((double)newWidth / originalBitmap.Width));
using var surface = SKSurface.Create(new SKImageInfo(newWidth, newHeight));
using var canvas = surface.Canvas;
var sourceRect = new SKRect(0, 0, originalBitmap.Width, originalBitmap.Height);
var destRect = new SKRect(0, 0, newWidth, newHeight);
canvas.DrawBitmap(originalBitmap, sourceRect, destRect);
using var resizedImage = surface.Snapshot();
using var data = resizedImage.Encode(SKEncodedImageFormat.Jpeg, 100);
return data.ToArray();
}
private async void OnTakePhoto(CheckListRowDTO checkListRowDTO)
{
try
{
if (MediaPicker.IsCaptureSupported)
{
await OnSave();
//await OnSave();
var photo = await MediaPicker.CapturePhotoAsync();
if (photo != null)
{
//using var stream = await photo.OpenReadAsync();
//using var ms = new MemoryStream();
//await stream.CopyToAsync(ms);
//byte[] photoBytes = ms.ToArray();
using var stream = await photo.OpenReadAsync();
using var originalBitmap = SKBitmap.Decode(stream);
int newWidth = 500;
int newHeight = (int)(originalBitmap.Height * ((double)newWidth / originalBitmap.Width));
using var surface = SKSurface.Create(new SKImageInfo(newWidth, newHeight));
using var canvas = surface.Canvas;
var sourceRect = new SKRect(0, 0, originalBitmap.Width, originalBitmap.Height);
var destRect = new SKRect(0, 0, newWidth, newHeight);
canvas.DrawBitmap(originalBitmap, sourceRect, destRect);
using var resizedImage = surface.Snapshot();
using var data = resizedImage.Encode(SKEncodedImageFormat.Jpeg, 100);
checkListRowDTO.Photo = data.ToArray();
checkListRowDTO.Photo = await ResizePicture(photo, 500);
checkListRowDTO.Answer = "Igen";
await _checkListService.UpdateCheckListRow(checkListRowDTO);