public void Map(PictureBox pictureBox1, List<int> drawdat, int count,List<GraphicsPath> gp)
{
Preprocess pe = new Preprocess();
List<int> drawdat1=new List<int>();
Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
Graphics g = Graphics.FromImage(bmp);
g.Clear(Color.White);
GraphicsPath gp0 = new GraphicsPath();//格网
GraphicsPath gp1 = new GraphicsPath();//赤道
GraphicsPath gp2 = new GraphicsPath();//点
GraphicsPath gp3 = new GraphicsPath();//线
GraphicsPath gp4 = new GraphicsPath();//点名
Pen p1 = new Pen(Color.Green, 1.0f);
Pen p2 = new Pen(Color.Red, 1.0f);
Pen p3 = new Pen(Color.Blue, 2.0f);
Pen p4 = new Pen(Color.Black, 1.0f);
Font f = new Font("宋体", 12.0f, FontStyle.Bold);
float x= pictureBox1.Width/20;
float y = pictureBox1.Height/11;
float e = pictureBox1.Height / 2;
//所有坐标放到第一个0-360度中 一个鸽子20度
for (int m = 0; m < count ; m++)
{
drawdat1.Add(pe.drawback(drawdat[m]));
}
//一个鸽子20度
for (int m = 0; m < (count / 2); m++)
{
drawdat1[2 * m] = ( Convert.ToInt32(e - (double)(drawdat1[2 * m]) / 20 * y));
drawdat1[2 * m + 1]=(Convert.ToInt32(Math.Round((double)(drawdat1[2 * m + 1])/20*x+x,0)));
}
// 格网
for (int i = 1; i < 20; i++)
{
//g.DrawLine(p1,x * i, y, x * i, 10 * y);
gp0.AddLine( x * i, y, x * i, 10*y);//p1
gp0.CloseFigure();
g.DrawPath(p1, gp0);
if (i < 11)
{
//g.DrawLine(p1,x, y * i, 19 * x, y * i);
gp0.AddLine(x, y * i, 19*x, y * i);//p1
gp0.CloseFigure();
g.DrawPath(p1, gp0);
}
//g.DrawLine(p2,x, e, 19 * x, e);
gp1.AddLine( x, e, 19 *x, e);//赤道 p2
g.DrawPath(p2, gp1);
}
//标点 连线 点名
for (int j = 0; j < (count / 4); j++)
{
//标点
Point po1 = new Point(drawdat1[4 * j+1], drawdat1[4 * j]);
gp2.AddEllipse( po1.X - 3, po1.Y - 3, 6, 6);
gp2.CloseFigure();
Point po2 = new Point(drawdat1[4 * j + 3], drawdat1[4 * j + 2]);
gp2.AddEllipse(po2.X - 3, po2.Y - 3, 6, 6);
gp2.CloseFigure();
g.FillPath(Brushes.Black, gp2);
//连线
gp3.AddLine(po1.X, po1.Y, po2.X, po2.Y);
gp3.CloseFigure();
g.DrawPath(p3, gp3);
StringFormat sf =new StringFormat();
gp4.AddString("P" + ((2 * j) + 1), new FontFamily("宋体"), 1,
20, new Point(po1.X - 12, po1.Y), sf);
gp4.CloseFigure();
gp4.AddString("P" + ((2 * j) + 2), new FontFamily("宋体"), 1,
20, new Point(po2.X - 12, po2.Y), sf);
gp4.CloseFigure();
g.FillPath(Brushes.Black, gp4);
}
pictureBox1.Image = bmp;
gp.Add(gp0);
gp.Add(gp1);
gp.Add(gp2);
gp.Add(gp3);
gp.Add(gp4);
}
//缩放图片
public void resize(object sender, MouseEventArgs e,PictureBox pictureBox1, List<GraphicsPath> gp)
{
PointF la = e.Location;
Bitmap bmp = new Bitmap(pictureBox1.Image);
Graphics g = Graphics.FromImage(bmp);
Pen p1 = new Pen(Color.Green, 1.0f);
Pen p2 = new Pen(Color.Red, 1.0f);
Pen p3 = new Pen(Color.Blue, 2.0f);
Pen p4 = new Pen(Color.Black, 1.0f);
Matrix mx = new Matrix();
if (e.Delta != 0)
{
if (e.Delta > 0)
{
g.Clear(Color.White);
mx.Scale(2, 2);
mx.Translate(-0.5f * la.X, -0.5f * la.Y);
for (int i = 0; i < 5; i++)
{
gp[i].Transform(mx);
}
g.DrawPath(p1, gp[0]);
g.DrawPath(p2, gp[1]);
g.FillPath(Brushes.Black, gp[2]);
g.DrawPath(p3, gp[3]);
g.FillPath(Brushes.Black, gp[4]);
pictureBox1.Image = bmp;
}
else
{
g.Clear(Color.White);
mx.Scale(0.5f, 0.5f);
mx.Translate(la.X, la.Y);
for (int i = 0; i < 5; i++)
{
gp[i].Transform(mx);
}
g.DrawPath(p1, gp[0]);
g.DrawPath(p2, gp[1]);
g.FillPath(Brushes.Black, gp[2]);
g.DrawPath(p3, gp[3]);
g.FillPath(Brushes.Black, gp[4]);
pictureBox1.Image = bmp;
}
}
}
c#对PictureBox中画图进行滚轮缩放(自用)
于 2024-05-31 16:33:35 首次发布