This commit is contained in:
otsmr 2026-01-25 12:39:53 +01:00
parent a029d2f4d5
commit 77166253ae

View file

@ -33,7 +33,7 @@ class _BackgroundLayerState extends State<BackgroundLayer> {
width: widget.layerData.image.width.toDouble(), width: widget.layerData.image.width.toDouble(),
height: widget.layerData.image.height.toDouble(), height: widget.layerData.image.height.toDouble(),
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
color: Colors.green, color: Colors.transparent,
child: CustomPaint( child: CustomPaint(
painter: UiImagePainter(scImage.image!), painter: UiImagePainter(scImage.image!),
), ),
@ -47,16 +47,25 @@ class UiImagePainter extends CustomPainter {
@override @override
void paint(Canvas canvas, Size size) { void paint(Canvas canvas, Size size) {
final imageSize = Size(image.width.toDouble(), image.height.toDouble());
final sizes = applyBoxFit(BoxFit.contain, imageSize, size);
final destRect = Alignment.center.inscribe(
sizes.destination,
Rect.fromLTWH(0, 0, size.width, size.height),
);
canvas.drawImageRect( canvas.drawImageRect(
image, image,
Rect.fromLTWH(0, 0, image.width.toDouble(), image.height.toDouble()), Rect.fromLTWH(0, 0, imageSize.width, imageSize.height),
Rect.fromLTWH(0, 0, size.width, size.height), destRect,
Paint(), Paint(),
); );
} }
@override @override
bool shouldRepaint(covariant CustomPainter oldDelegate) { bool shouldRepaint(covariant UiImagePainter oldDelegate) {
return false; return image != oldDelegate.image;
} }
} }