- 积分
- 40165
- 好友
- 记录
- 主题
- 帖子
- 听众
- 收听
|
楼主 |
发表于 2012-11-13 11:33:36
|
显示全部楼层
[code=csharp]/// <summary>
/// 图像缩放
/// </summary>
/// <param name="dx">横向缩放比列</param>
/// <param name="dy">纵向缩放比列</param>
private void ScalePictureBox(float dx,float dy)
{
this.pictureBox1.Location = new Point(0, 0);
this.panel1.AutoScrollPosition = new Point(0, 0);
SizeF sf = new SizeF(dx, dy);
this.pictureBox1.Scale(sf);
}
/// <summary>
/// 图像缩放比列及放大或缩小幅大
/// </summary>
/// <param name="dx">横向缩放比列</param>
/// <param name="dy">纵向缩放比列</param>
/// <param name="zoomFlag">放大缩小标志,false代表缩小,true代表放大</param>
private void ZoomImage( float dx, float dy,bool zoomFlag)
{
//放大到5倍时停止放大
if (zoomFlag)
{
if (this.pictureBox1 .Width >= 5 * this.pictureBox1.Image.Width && this.pictureBox1 .Height>= 5 * this.pictureBox1.Image.Height)
return;
ScalePictureBox(dx,dy);
}
//图像的宽或高大于等于panel的宽或高时,则缩小到填充整个panel时为止,否则缩小到原图大小
else
{
//图像比panel大,且已缩小到小于等于panel时为止
if ((this.pictureBox1.Image.Width >= this.panel1.Width || this.pictureBox1.Image.Height >= this.panel1.Height)
&& (this.pictureBox1.Width <= this.panel1.Width && this.pictureBox1.Height <= this.panel1.Height))
{
return;
}
//图像比panel小
else if (this.pictureBox1.Image.Width < this.panel1.Width && this.pictureBox1.Image.Height < this.panel1.Height)
{
//已缩小到原图大小时为止
if (this.pictureBox1.Width <= this.pictureBox1.Image.Width || this.pictureBox1.Height <= this.pictureBox1.Image.Height)
{
return;
}
ScalePictureBox(dx, dy);
}
//图像比panel大,且仍可缩小到填充整个panel
else
{
ScalePictureBox(dx, dy);
if (this.pictureBox1.Width <= this.panel1.Width && this.pictureBox1.Height <= this.panel1.Height)
{
this.pictureBox1.Width = this.panel1.Width;
this.pictureBox1.Height = this.panel1.Height;
}
}
}
}[/code]
|
|