Elvileg jó, meg a mentés is.
This commit is contained in:
@@ -0,0 +1,62 @@
|
|||||||
|
using SkiaSharp;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WorkFlowCheck.MAUI.Helper
|
||||||
|
{
|
||||||
|
public static class ImageHelper
|
||||||
|
{
|
||||||
|
public static string ResizeAndSaveImage(byte[] imageBytes, int id, int targetWidth = 50)
|
||||||
|
{
|
||||||
|
// Átméretezett fájl elérési útja
|
||||||
|
var filename = Path.Combine(FileSystem.CacheDirectory, $"wfc_{id}_photo.jpg");
|
||||||
|
|
||||||
|
if (File.Exists(filename))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File.Delete(filename);
|
||||||
|
// opcionálisan logolhatsz
|
||||||
|
// Console.WriteLine($"Törölve: {filename}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//Console.WriteLine($"Hiba a fájl törlésekor: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Eredeti kép betöltése
|
||||||
|
using var inputStream = new MemoryStream(imageBytes);
|
||||||
|
using var original = SKBitmap.Decode(inputStream);
|
||||||
|
|
||||||
|
if (original == null)
|
||||||
|
throw new InvalidOperationException("A kép nem olvasható vagy hibás.");
|
||||||
|
|
||||||
|
// Új szélesség és magasság arányosan
|
||||||
|
|
||||||
|
int targetHeight = (int)(original.Height * ((double)targetWidth / original.Width));
|
||||||
|
|
||||||
|
// Új üres bitmap létrehozása
|
||||||
|
using var resizedSurface = SKSurface.Create(new SKImageInfo(targetWidth, targetHeight));
|
||||||
|
using var canvas = resizedSurface.Canvas;
|
||||||
|
|
||||||
|
canvas.Clear(SKColors.White); // választható háttérszín
|
||||||
|
|
||||||
|
var srcRect = new SKRect(0, 0, original.Width, original.Height);
|
||||||
|
var destRect = new SKRect(0, 0, targetWidth, targetHeight);
|
||||||
|
canvas.DrawBitmap(original, srcRect, destRect);
|
||||||
|
|
||||||
|
using var resizedImage = resizedSurface.Snapshot();
|
||||||
|
using var imageData = resizedImage.Encode(SKEncodedImageFormat.Jpeg, 90);
|
||||||
|
|
||||||
|
// Mentés fájlba
|
||||||
|
using var fileStream = File.OpenWrite(filename);
|
||||||
|
imageData.SaveTo(fileStream);
|
||||||
|
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,15 @@
|
|||||||
using System.ComponentModel;
|
using SkiaSharp;
|
||||||
|
using System.ComponentModel;
|
||||||
using WorkFlowCheck.Common.DTO;
|
using WorkFlowCheck.Common.DTO;
|
||||||
|
using WorkFlowCheck.MAUI.Helper;
|
||||||
|
|
||||||
namespace WorkFlowCheck.MAUI.Pages.CheckList
|
namespace WorkFlowCheck.MAUI.Pages.CheckList
|
||||||
{
|
{
|
||||||
public class CheckListRowCS : INotifyPropertyChanged
|
public class CheckListRowCS : INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
private byte[] _photoBytes;
|
private byte[] _photoBytes;
|
||||||
private ImageSource? _photo;
|
//private ImageSource? _photo;
|
||||||
|
private string? _photoPath;
|
||||||
|
|
||||||
public event PropertyChangedEventHandler PropertyChanged;
|
public event PropertyChangedEventHandler PropertyChanged;
|
||||||
|
|
||||||
@@ -18,6 +21,7 @@ namespace WorkFlowCheck.MAUI.Pages.CheckList
|
|||||||
public string Answer { get; set; } = null!;
|
public string Answer { get; set; } = null!;
|
||||||
public bool? AnswerYes { get; set; } = null!;
|
public bool? AnswerYes { get; set; } = null!;
|
||||||
public bool? AnswerNo { get; set; } = null!;
|
public bool? AnswerNo { get; set; } = null!;
|
||||||
|
|
||||||
public byte[] PhotoBytes
|
public byte[] PhotoBytes
|
||||||
{
|
{
|
||||||
get => _photoBytes;
|
get => _photoBytes;
|
||||||
@@ -26,37 +30,58 @@ namespace WorkFlowCheck.MAUI.Pages.CheckList
|
|||||||
if (_photoBytes != value)
|
if (_photoBytes != value)
|
||||||
{
|
{
|
||||||
_photoBytes = value;
|
_photoBytes = value;
|
||||||
_photo = null;
|
//_photo = null;
|
||||||
OnPropertyChanged(nameof(PhotoBytes));
|
_photoPath = null;
|
||||||
OnPropertyChanged(nameof(Photo));
|
//OnPropertyChanged(nameof(PhotoBytes));
|
||||||
|
//OnPropertyChanged(nameof(Photo));
|
||||||
|
OnPropertyChanged(nameof(PhotoPath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public ImageSource Photo
|
//public ImageSource Photo
|
||||||
|
//{
|
||||||
|
// get
|
||||||
|
// {
|
||||||
|
// if (_photo == null)
|
||||||
|
// {
|
||||||
|
// if (PhotoBytes != null && PhotoBytes.Length > 0)
|
||||||
|
// {
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// var bytesCopy = PhotoBytes.ToArray();
|
||||||
|
// _photo = ImageSource.FromStream(() => new MemoryStream(bytesCopy));
|
||||||
|
// }
|
||||||
|
// catch
|
||||||
|
// {
|
||||||
|
// _photo = ImageSource.FromFile("noimage.png");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// _photo = ImageSource.FromFile("noimage.png");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return _photo;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
public string PhotoPath
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_photo == null)
|
if (_photoPath == null)
|
||||||
{
|
{
|
||||||
if (PhotoBytes != null && PhotoBytes.Length > 0)
|
if (PhotoBytes != null && PhotoBytes.Length > 0)
|
||||||
{
|
{
|
||||||
try
|
_photoPath = ImageHelper.ResizeAndSaveImage(PhotoBytes, Id, 100);
|
||||||
{
|
|
||||||
var bytesCopy = PhotoBytes.ToArray();
|
|
||||||
_photo = ImageSource.FromStream(() => new MemoryStream(bytesCopy));
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
_photo = ImageSource.FromFile("noimage.png");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_photo = ImageSource.FromFile("noimage.png");
|
_photoPath = "noimage.png";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return _photoPath;
|
||||||
return _photo;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -130,12 +130,12 @@
|
|||||||
<Label Text="{Binding OperationDescription}" BackgroundColor="WhiteSmoke" Grid.Column="1" />
|
<Label Text="{Binding OperationDescription}" BackgroundColor="WhiteSmoke" Grid.Column="1" />
|
||||||
<Grid Grid.Column="2" ColumnDefinitions="Auto,Auto" VerticalOptions="Center">
|
<Grid Grid.Column="2" ColumnDefinitions="Auto,Auto" VerticalOptions="Center">
|
||||||
<Image Grid.Column="0"
|
<Image Grid.Column="0"
|
||||||
WidthRequest="95"
|
WidthRequest="65"
|
||||||
HeightRequest="120"
|
HeightRequest="90"
|
||||||
Aspect="AspectFill"
|
Aspect="AspectFill"
|
||||||
Margin="0,0,10,0"
|
Margin="0,0,10,0"
|
||||||
VerticalOptions="Center"
|
VerticalOptions="Center"
|
||||||
Source="{Binding Photo}" >
|
Source="{Binding PhotoPath}" >
|
||||||
</Image>
|
</Image>
|
||||||
<Button Text="📷" Grid.Column="1"
|
<Button Text="📷" Grid.Column="1"
|
||||||
VerticalOptions="Center"
|
VerticalOptions="Center"
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ public partial class CheckListWorkPage : ContentPage
|
|||||||
{
|
{
|
||||||
if (MediaPicker.IsCaptureSupported)
|
if (MediaPicker.IsCaptureSupported)
|
||||||
{
|
{
|
||||||
await OnSave(false);
|
//await OnSave(false);
|
||||||
var photo = await MediaPicker.CapturePhotoAsync();
|
var photo = await MediaPicker.CapturePhotoAsync();
|
||||||
if (photo != null)
|
if (photo != null)
|
||||||
{
|
{
|
||||||
@@ -196,7 +196,7 @@ public partial class CheckListWorkPage : ContentPage
|
|||||||
checkListRowDTO.Answer = "Igen";
|
checkListRowDTO.Answer = "Igen";
|
||||||
|
|
||||||
await _checkListService.UpdateCheckListRow(checkListRowDTO, true);
|
await _checkListService.UpdateCheckListRow(checkListRowDTO, true);
|
||||||
await LoadCheckPointCheckListRows();
|
//await LoadCheckPointCheckListRows();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 6.0 KiB After Width: | Height: | Size: 2.2 KiB |
@@ -167,10 +167,17 @@ namespace WorkFlowCheck.MAUI.Services
|
|||||||
.Where(w => w.Id == checkListRowDTO.Id).FirstOrDefaultAsync();
|
.Where(w => w.Id == checkListRowDTO.Id).FirstOrDefaultAsync();
|
||||||
if (checkListRow != null)
|
if (checkListRow != null)
|
||||||
{
|
{
|
||||||
checkListRow.Answer = checkListRowDTO.Answer;
|
if (checkListRow.Answer != checkListRowDTO.Answer)
|
||||||
|
{
|
||||||
|
checkListRow.Answer = checkListRowDTO.Answer;
|
||||||
|
}
|
||||||
|
|
||||||
if (checkListRowDTO.Photo != null && checkListRowDTO.Photo.Length > 0 && withPhoto)
|
if (checkListRowDTO.Photo != null && checkListRowDTO.Photo.Length > 0 && withPhoto)
|
||||||
{
|
{
|
||||||
checkListRow.Photo = checkListRowDTO.Photo;
|
if (!checkListRow.Photo.SequenceEqual(checkListRowDTO.Photo ?? Array.Empty<byte>()))
|
||||||
|
{
|
||||||
|
checkListRow.Photo = checkListRowDTO.Photo ?? Array.Empty<byte>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await _dbContext.SaveChangesAsync();
|
await _dbContext.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user