我有一个图像控制类,放大/缩小,填充屏幕,并执行1:1的比例(全部由4个不同的按钮控制),但是当屏幕分辨率大于1280 ×1024,我的填充屏幕和1:1的比例不这样做,他们都应该缩放和图像填充屏幕
public void ZoomActual()
{
m_translateTransform.BeginAnimation(TranslateTransform.XProperty, CreateAnimation(0));
m_translateTransform.BeginAnimation(TranslateTransform.YProperty, CreateAnimation(0));
m_zoomFactor.BeginAnimation(ScaleTransform.ScaleXProperty, CreateAnimation(1));
m_zoomFactor.BeginAnimation(ScaleTransform.ScaleYProperty, CreateAnimation(1));
} //1:1 ratio button control
/// <summary>
/// This function is used to fill the screen with the current picture on the zoomandpan Control
/// </summary>
public void ZoomFit()
{
double screen_height = ActualHeight;
double screen_width = ActualWidth;
double image_width = m_source_child.ActualWidth;
double image_height = m_source_child.ActualHeight;
double image_ratio = image_width/image_height;
double screen_ratio = screen_width/screen_height;
if (image_width > image_height)
{
m_translateTransform.BeginAnimation(TranslateTransform.XProperty, CreateAnimation(0));
m_translateTransform.BeginAnimation(TranslateTransform.YProperty, CreateAnimation(0));
m_zoomFactor.BeginAnimation(ScaleTransform.ScaleXProperty, CreateAnimation(1/screen_ratio * image_ratio)); //width
m_zoomFactor.BeginAnimation(ScaleTransform.ScaleYProperty, CreateAnimation(1/screen_ratio * image_ratio)); //height
}
else
{
m_translateTransform.BeginAnimation(TranslateTransform.XProperty, CreateAnimation(0));
m_translateTransform.BeginAnimation(TranslateTransform.YProperty, CreateAnimation(0));
m_zoomFactor.BeginAnimation(ScaleTransform.ScaleXProperty, CreateAnimation((screen_ratio * image_ratio))); //width
m_zoomFactor.BeginAnimation(ScaleTransform.ScaleYProperty, CreateAnimation((screen_ratio * image_ratio))); //height
}
} //fillscreen button control
/// <summary>
/// This function is used to control the animations of the ZoomandPan. Animations consist of Zooming in
/// and out of a picture and allows panning of the displayed image
/// </summary>
/// <param name="a_toValue">used for zoom in percentage [currently set at: 1.5 (150%)]</param>
/// <returns>Animation values image</returns>
private DoubleAnimation CreateAnimation(double a_toValue)
{
var dubAni = new DoubleAnimation(a_toValue, new Duration(TimeSpan.FromMilliseconds(300)))
{
AccelerationRatio = 0.1,
DecelerationRatio = 0.9,
FillBehavior = FillBehavior.HoldEnd
};
dubAni.Freeze();
return dubAni;
} //Animation value setter
/// <summary>
/// DoZoom is used for executing the physical zoom of the picture, enlarges or shrinks image depending
/// on CreateAnimation values
/// </summary>
/// <param name="a_deltaZoom">Determinded to be + or -. can be set by mousewheel and/or buttons. Determines Zoom in/out</param>
/// <param name="a_mousePosition">Current positon of mouse</param>
/// <param name="a_physicalPositon">refrence to last area mousePosition was on image</param>
private void DoZoom(Double a_deltaZoom, Point a_mousePosition, Point a_physicalPositon)
{
double currentZoom = m_zoomFactor.ScaleX;
currentZoom *= a_deltaZoom;
if (currentZoom < MinZoom)
currentZoom = MinZoom;
else if (currentZoom > MaxZoom)
currentZoom = MaxZoom;
m_translateTransform.BeginAnimation(TranslateTransform.XProperty, CreateAnimation(-1 * (a_mousePosition.X * currentZoom - a_physicalPositon.X)));
m_translateTransform.BeginAnimation(TranslateTransform.YProperty, CreateAnimation(-1 * (a_mousePosition.Y * currentZoom - a_physicalPositon.Y)));
m_zoomFactor.BeginAnimation(ScaleTransform.ScaleXProperty, CreateAnimation(currentZoom));
m_zoomFactor.BeginAnimation(ScaleTransform.ScaleYProperty, CreateAnimation(currentZoom));
} //Zoom animation
当我这样它不会做什么应该我的意思是这样的:如果我的屏幕的分辨率1280 x 1024或更低,填充屏幕会填满屏幕,1:1比例会给出图片的实际尺寸,任何大于1280 x 1024的分辨率都会导致填充屏幕控制使图像变小(在内部画布),而不是将整个图像放在窗口上,并且采用1:1的比例控制将有一个小的差距,只是空白的权利。提供的任何帮助非常感谢,我对图像控制有点新,所以这可能看起来很琐碎。对不起回合
你的XAML是什么样的? 'Image'控件根据给定的空间和'Stretch'属性来进行自己的拟合。 – RandomEngy
什么是附加到m_zoomFactor和m_translateTransform故事板?请给出理解代码所需的一切。 – RandomEngy