mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 10:56:31 +00:00
fix editing tiled images
This commit is contained in:
@@ -307,15 +307,8 @@ public class AnnotatorEventHandler(
|
||||
if (!File.Exists(imgPath))
|
||||
{
|
||||
var source = (mainWindow.Editor.BackgroundImage.Source as BitmapSource)!;
|
||||
if (source.PixelWidth <= Constants.AI_TILE_SIZE * 2 && source.PixelHeight <= Constants.AI_TILE_SIZE * 2) // Allow to be up to 2560*2560 to save to 1280*1280
|
||||
{
|
||||
//Save image
|
||||
await using var stream = new FileStream(imgPath, FileMode.Create);
|
||||
var encoder = new JpegBitmapEncoder();
|
||||
encoder.Frames.Add(BitmapFrame.Create(source));
|
||||
encoder.Save(stream);
|
||||
await stream.FlushAsync(cancellationToken);
|
||||
}
|
||||
if (new Size(source.PixelWidth, source.PixelHeight).FitSizeForAI())
|
||||
await source.SaveImage(imgPath, cancellationToken);
|
||||
else
|
||||
{
|
||||
//Tiling
|
||||
@@ -335,14 +328,9 @@ public class AnnotatorEventHandler(
|
||||
var annotationName = $"{formState.MediaName}{Constants.SPLIT_SUFFIX}{res.Tile.Left:0000}_{res.Tile.Top:0000}!".ToTimeName(time);
|
||||
|
||||
var tileImgPath = Path.Combine(dirConfig.Value.ImagesDirectory, $"{annotationName}{Constants.JPG_EXT}");
|
||||
await using var tileStream = new FileStream(tileImgPath, FileMode.Create);
|
||||
var bitmap = new CroppedBitmap(source, new Int32Rect((int)res.Tile.Left, (int)res.Tile.Top, (int)res.Tile.Width, (int)res.Tile.Height));
|
||||
|
||||
var tileEncoder = new JpegBitmapEncoder { Frames = [BitmapFrame.Create(bitmap)] };
|
||||
tileEncoder.Save(tileStream);
|
||||
await tileStream.FlushAsync(cancellationToken);
|
||||
tileStream.Close();
|
||||
|
||||
await bitmap.SaveImage(tileImgPath, cancellationToken);
|
||||
|
||||
var frameSize = new Size(res.Tile.Width, res.Tile.Height);
|
||||
var detections = res.Detections
|
||||
.Select(det => det.ReframeToSmall(res.Tile))
|
||||
|
||||
Reference in New Issue
Block a user