pictureBox图像scalling [英] pictureBox image scalling
问题描述
我有一个绘制了pictureBox的代码,但是在绘制之后,该行将加载到pictureBox中的图像移位。我希望在整个时间内将图像加载到pictureBox中,然后才能正确缩放。例如图片3000x2000在800x600图片框中可见。
感谢您的帮助。
我有绘制线条的代码
I have a code that draws over pictureBox but after draw the line shifts the image loaded into pictureBox. I wish the image loaded in pictureBox whole time he was properly scaled. For example picture 3000x2000 visible in the 800x600 pictureBox.
Thank you for any help.
I have code to draw lines
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
pointArray[iNumberofClicks].X = e.X;
pointArray[iNumberofClicks].Y = e.Y;
Pen PenSpikes = new Pen(Color.Green);
SolidBrush solidBrush = new SolidBrush(Color.Blue);
iNumberofClicks++;
if (iNumberofClicks > 1)
{
Point[] CurrentpointArray = new Point[iNumberofClicks];
for (int i = 0; i < iNumberofClicks; i++)
{
CurrentpointArray[i].X = pointArray[i].X;
CurrentpointArray[i].Y = pointArray[i].Y;
}
Bitmap canvas = new Bitmap(pictureBox1.Width, pictureBox1.Height);
Graphics offScreenDC = Graphics.FromImage(canvas);
// New line!
offScreenDC.DrawImage(pictureBox1.Image, new Point());
offScreenDC.DrawLines(PenSpikes, CurrentpointArray);
pictureBox1.Image = canvas;
offScreenDC.Dispose();
}
}
推荐答案
我认为你需要绘制一套通过点击它将点放在picture_Box上。您使用此代码执行的操作是,在鼠标单击时收集点集,将点集复制到局部数组,使用本地阵列绘制线创建图像,然后将图像设置为pictureBox1。 br />
我认为最好的方法就是在图片框的Paint事件中绘制线条。
更改鼠标事件如下。
I think you need to draw set of lines while you put points on a picture_Box by clicking on it. What you do with this code is, you collect the set of points as the mouse clicks, copy the set of points in to a local array, create an image with drawing lines with the local array and then set the image to the pictureBox1.
I think the best way is to do this is drawing lines with in the "Paint" event of the picture box.
change the mouse event as the follow.
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
pointArray[iNumberofClicks].X = e.X;
pointArray[iNumberofClicks].Y = e.Y;
iNumberofClicks++;
pictureBox1.Refresh();
}
//this is the registered paint event of the pictureBox1
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
if(iNumberofClicks >1)
{
Pen PenSpikes = new Pen(Color.Green);
Graphics g = e.Graphics;
g.DrawLines(PenSpikes, pointArray);
}
}
当你设置新点时,你可以看到新线。如果你需要放大绘图,你可以简单地将数组中点的x和y坐标乘以你需要的比例因子,然后调用pictureBox1.Refresh()。
When ever you put a new point, you can see the new line. If you need to scale up the drawing you can simply multiply the x and y coordinates of the points in the array by the scale factor you need and then call pictureBox1.Refresh().
private void scaleDrawing(double factor)
{
for (int i = 0; i < iNumberofClicks; i++)
{
pointArray[i].X = (int)pointArray[i].X*factor;
pointArray[i].Y = (int)pointArray[i].Y*factor;
}
pictureBox1.Refresh();
}
这就是我理解你的问题的方法。请澄清我是否错了。
This is how I understand your question. Please clarify if I'm wrong.
这篇关于pictureBox图像scalling的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!