请问 如何 以一个点 为中心 等比例 缩放 图片?
大家好!
我在panel中 放置了 一个picturebox ,如果 图片太大 panel不能显示 整个图片,我想以panel显示的那块图片的一部分, 矩形的中心为 中心缩放 等比例图片。
还有一个问题就是,如何调用 鼠标的中键来实现缩放。
谢谢!
------解决方案--------------------把picturebox的SizeMode属性设置为Zoom就可以了
------解决方案--------------------楼上正解;
------解决方案--------------------private Point mousePosition = new Point(0, 0);
public Form1()
{
InitializeComponent();
}
private void minPanel_Paint(object sender, PaintEventArgs e)
{
Graphics g = this.minPanel.CreateGraphics();
Image img = Image.FromFile(Application.StartupPath + @ "\7.jpg ");
g.DrawImage(img, this.minPanel.ClientRectangle, 0, 0, img.Width, img.Height, System.Drawing.GraphicsUnit.Pixel);
}
private void minPanel_MouseDown(object sender, MouseEventArgs e)
{
this.controlframe.Left = e.X;
this.controlframe.Top = e.Y;
DrawBig();
DrawSmall();
}
private void controlframe_Paint(object sender, PaintEventArgs e)
{
DrawSmall();
}
private void controlframe_MouseUp(object sender, MouseEventArgs e)
{
DrawSmall();
DrawBig();
}
private void controlframe_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (e.X > = 0 && e.X <= this.minPanel.ClientRectangle.Width && e.Y > = 0 && e.Y <= this.minPanel.ClientRectangle.Height)
{
this.controlframe.Left = e.X + this.mousePosition.X;
this.controlframe.Top = e.Y + this.mousePosition.Y;
DrawSmall();
DrawBig();
}
}
}
private void controlframe_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.mousePosition.X = this.controlframe.Left;
this.mousePosition.Y = this.controlframe.Top;
this.DrawSmall();
this.DrawBig();
//this.Dispose;
}
}
private void DrawSmall()
{
Graphics g = this.controlframe.CreateGraphics();
Bitmap bmp = new Bitmap((Bitmap)Bitmap.FromFile(Application.StartupPath + @ "\7.jpg "), new Size(this.minPanel.Width, this.minPanel.Height));
g.DrawImage(bmp, this.controlframe.ClientRectangle, this.controlframe.Left, this.controlframe.Top, this.controlframe.ClientRectangle.Width, this.controlframe.ClientRectangle.Height, System.Drawing.GraphicsUnit.Pixel);
g.Dispose();
this.controlframe.Update();
}
private void DrawBig()
{
Graphics g = this.maxPanel.CreateGraphics();
Image img = Image.FromFile(Application.StartupPath + @ "\7.jpg ");
g.DrawImage(img, this.maxPanel.ClientRectangle, this.controlframe.Left, this.controlframe.Top, this.maxPanel.ClientRectangle.Width, this.maxPanel.ClientRe