Image 保持图像的纵横比?
我使用pictureBox显示从服务器接收到的图像,但我的问题是compact框架中的图片框只有三种大小模式 拉伸图像、普通图像、中心图像 我得到的图片通常都比较大,所以我必须使用Stretchimage模式。但随后,纵横比保持不变,因此显示的图像会失真Image 保持图像的纵横比?,image,windows-mobile,aspect-ratio,Image,Windows Mobile,Aspect Ratio,我使用pictureBox显示从服务器接收到的图像,但我的问题是compact框架中的图片框只有三种大小模式 拉伸图像、普通图像、中心图像 我得到的图片通常都比较大,所以我必须使用Stretchimage模式。但随后,纵横比保持不变,因此显示的图像会失真 那么,他们到底能解决这个问题吗?我终于找到了我问题的答案,答案就在这里----- float actualHeight=myImg.高度; 浮动实际宽度=最小宽度; 浮动高度=实际宽度/实际高度; float maxRatio=(float)t
那么,他们到底能解决这个问题吗?我终于找到了我问题的答案,答案就在这里-----
float actualHeight=myImg.高度;
浮动实际宽度=最小宽度;
浮动高度=实际宽度/实际高度;
float maxRatio=(float)this.Width/this.Height;
如果(imgRatio!=最大比率)
{
if(imgRatio
但在执行此操作之前,请将图片框大小模式保持为stretchImage我认为您的意思是纵横比“未保持”,对吗?
float actualHeight = myImg.Height;
float actualWidth = myImg.Width;
float imgRatio = actualWidth / actualHeight;
float maxRatio = (float)this.Width / this.Height;
if(imgRatio!=maxRatio)
{
if (imgRatio < maxRatio)
{
imgRatio = this.Height / actualHeight;
actualWidth = imgRatio * actualWidth;
actualHeight = this.Height;
}
else
{
imgRatio = this.Width / actualWidth;
actualHeight = imgRatio * actualHeight;
actualWidth = this.Width;
}
}
pictureBox.Size=new Size((int)actualWidth,(int)actualHeight);
pictureBox.Location = new Point((int)((this.Width - actualWidth) / 2), (int)((this.Height - actualHeight) / 2));