修复报告页面图像自适应的问题

This commit is contained in:
zhengxuan.zhang
2026-05-15 11:00:18 +08:00
parent cf8248abfb
commit bc8a0eadfb
2 changed files with 10 additions and 28 deletions
+9 -27
View File
@@ -237,33 +237,13 @@ namespace XplorePlane.Controls
private void ExecuteFitToView() private void ExecuteFitToView()
{ {
if (_imageElement == null || _containerBorder == null || Source == null) if (_imageElement == null || Source == null)
return; return;
double containerWidth = _containerBorder.ActualWidth; // With Stretch="Uniform", the Image control already fits the image to the container.
double containerHeight = _containerBorder.ActualHeight; // FitToView simply resets the transform to identity (scale=1, translate=0).
_scaleTransform.ScaleX = 1.0;
if (containerWidth <= 0 || containerHeight <= 0) _scaleTransform.ScaleY = 1.0;
return;
double imageWidth = Source.PixelWidth;
double imageHeight = Source.PixelHeight;
if (imageWidth <= 0 || imageHeight <= 0)
return;
// Calculate scale to fit
double scaleX = containerWidth / imageWidth;
double scaleY = containerHeight / imageHeight;
double scale = Math.Min(scaleX, scaleY);
// Clamp to min/max
scale = Math.Max(MinScale, Math.Min(MaxScale, scale));
_scaleTransform.ScaleX = scale;
_scaleTransform.ScaleY = scale;
// Center the image
_translateTransform.X = 0; _translateTransform.X = 0;
_translateTransform.Y = 0; _translateTransform.Y = 0;
} }
@@ -279,8 +259,10 @@ namespace XplorePlane.Controls
if (containerWidth <= 0 || containerHeight <= 0) if (containerWidth <= 0 || containerHeight <= 0)
return; return;
double imageWidth = Source.PixelWidth * _scaleTransform.ScaleX; // With Stretch="Uniform", the Image control's ActualWidth/Height represents
double imageHeight = Source.PixelHeight * _scaleTransform.ScaleY; // the displayed size at scale=1. Multiply by current scale for actual rendered size.
double imageWidth = _imageElement.ActualWidth * _scaleTransform.ScaleX;
double imageHeight = _imageElement.ActualHeight * _scaleTransform.ScaleY;
// Calculate bounds // Calculate bounds
double maxOffsetX = Math.Max(0, (imageWidth - containerWidth) / 2); double maxOffsetX = Math.Max(0, (imageWidth - containerWidth) / 2);
+1 -1
View File
@@ -143,7 +143,7 @@
VerticalAlignment="Center" VerticalAlignment="Center"
RenderOptions.BitmapScalingMode="HighQuality" RenderOptions.BitmapScalingMode="HighQuality"
Source="{TemplateBinding Source}" Source="{TemplateBinding Source}"
Stretch="None" /> Stretch="Uniform" />
<!-- Fallback Placeholder --> <!-- Fallback Placeholder -->
<Grid x:Name="PART_Placeholder" Visibility="Collapsed"> <Grid x:Name="PART_Placeholder" Visibility="Collapsed">