我有一个pictureBox在panel控件里,我想对pictureBox的尺寸进行一定比例缩放,但是希望是按当前视点中心点进行缩放(就是panel的中心),如果直接 pictureBox1.Width = Convert.ToInt32(MapWidth * MapMultiple);的话,是基于pictureBox的左上为锚点了,这里的算法是怎样的啊?
如图:这是希望达到的效果,但是pictureBox1.location应该按照蓝色线条进行移动,这里算法一直没明白。
不考虑锚点的情况
int MapHigh, MapWidth;//地图初始大小
MapHigh = pictureBox1.Height;
MapWidth = pictureBox1.Width;
double MapMultiple=1;//地图放大倍数 if (MapMultiple >0.1)
{
MapMultiple = MapMultiple - 0.05;
}
else
{
MapMultiple = 0.05;
} pictureBox1.Width = Convert.ToInt32(MapWidth * MapMultiple);
pictureBox1.Height = Convert.ToInt32(MapHigh * MapMultiple);
如图:这是希望达到的效果,但是pictureBox1.location应该按照蓝色线条进行移动,这里算法一直没明白。
不考虑锚点的情况
int MapHigh, MapWidth;//地图初始大小
MapHigh = pictureBox1.Height;
MapWidth = pictureBox1.Width;
double MapMultiple=1;//地图放大倍数 if (MapMultiple >0.1)
{
MapMultiple = MapMultiple - 0.05;
}
else
{
MapMultiple = 0.05;
} pictureBox1.Width = Convert.ToInt32(MapWidth * MapMultiple);
pictureBox1.Height = Convert.ToInt32(MapHigh * MapMultiple);
panel.ClientRectangle.Width/2-pictureBox1.Width/2,
panel.ClientRectangle.Height/2-pictureBox1.Height/2,
)
private void button_samll_Click(object sender, EventArgs e)
{
if (MapMultiple > 0.1)
{
MapMultiple = MapMultiple - 0.05;
}
else
{
MessageBox.Show("已缩放最小!");
return;
}
MapAnchorX = Convert.ToInt32(pictureBox1.Location.X + pictureBox1.Width * 0.005)+5;
MapAnchorY = Convert.ToInt32(pictureBox1.Location.Y + pictureBox1.Height * 0.005)+5;
pictureBox1.Location = new Point(MapAnchorX, MapAnchorY);
pictureBox1.Width = Convert.ToInt32(MapWidth * MapMultiple);
pictureBox1.Height = Convert.ToInt32(MapHigh * MapMultiple);
}
地图缩放:Zoom(double scale)
坐标转换算法:屏幕坐标和地图坐标的转换算法基本这几点,不过目前市面上就没有几个真正实现的离线地图平台软件。
1277874734