Skip to content

Commit cb3c7e3

Browse files
Merge branch 'main' into develop
2 parents 43504af + f3b35b3 commit cb3c7e3

2 files changed

Lines changed: 52 additions & 11 deletions

File tree

Logic/ViewModels/ToolbarViewModel.cs

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,47 @@ public ToolbarViewModel(
532532
canvas.Restore();
533533
}
534534

535-
i = j;
535+
ImportImageCommand = ReactiveCommand.CreateFromTask(async () =>
536+
{
537+
try
538+
{
539+
var result = await FilePicker.Default.PickAsync(new PickOptions
540+
{
541+
PickerTitle = "Select an image to import",
542+
FileTypes = FilePickerFileType.Images
543+
});
544+
545+
if (result != null)
546+
{
547+
string path = result.FullPath;
548+
549+
// On platforms where FullPath is not available, copy to cache
550+
if (string.IsNullOrEmpty(path))
551+
{
552+
path = Path.Combine(FileSystem.CacheDirectory, result.FileName);
553+
using var sourceStream = await result.OpenReadAsync();
554+
using var destStream = File.Create(path);
555+
await sourceStream.CopyToAsync(destStream);
556+
}
557+
558+
// Load with downsampling (max 2048x2048)
559+
var bitmap = await this.bitmapCacheManager.GetBitmapAsync(path, 2048, 2048);
560+
if (bitmap != null)
561+
{
562+
var drawableImage = new DrawableImage(bitmap)
563+
{
564+
SourcePath = path
565+
};
566+
567+
this.layerFacade.CurrentLayer?.Elements.Add(drawableImage);
568+
this.messageBus.SendMessage(new CanvasInvalidateMessage());
569+
this.layerFacade.SaveState();
570+
}
571+
}
572+
}
573+
catch (Exception ex)
574+
{
575+
System.Diagnostics.Debug.WriteLine($"Error importing image: {ex.Message}");
536576
}
537577
}
538578

@@ -551,12 +591,13 @@ public ToolbarViewModel(
551591
using var data = image.Encode(SKEncodedImageFormat.Png, 100);
552592
using var stream = data.AsStream();
553593

554-
var result = await this.fileSaver.SaveAsync("lunadraw_canvas.png", stream);
555-
}
556-
catch (Exception ex)
557-
{
558-
System.Diagnostics.Debug.WriteLine($"Error saving image: {ex.Message}");
559-
}
560-
});
561-
}
562-
}
594+
var result = await this.fileSaver.SaveAsync("lunadraw_canvas.png", stream);
595+
}
596+
catch (Exception ex)
597+
{
598+
System.Diagnostics.Debug.WriteLine($"Error saving image: {ex.Message}");
599+
}
600+
});
601+
}
602+
}
603+
}

tests/LunaDraw.Tests/SelectionViewModelTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,4 @@ public void DuplicateCommand_ShouldCopyAndPasteElement()
110110
Assert.Equal(element.Bounds.Top + 10, cloneBounds.Top);
111111
}
112112
}
113-
}
113+
}

0 commit comments

Comments
 (0)