【发布时间】:2017-01-11 05:56:41
【问题描述】:
我的应用程序中有一个Size 400X400 的图片框。图片框的SizeMode 设置为Zoomed。我已经在图片框中加载了一个 700X446 的 png 图像。
我有以下问题,
即使我沿着红色路径绘制一条黑色直线,实际上它是沿着加载的图像显示的,而不是透视图。
我该如何解决这个问题?
P.S.我只想在图像上绘制,而不是整个图片框。
源代码:
public partial class MainForm : Form
{
Bitmap _inputImage = null;
//Graphics _imageGraphics = null;
#region ctor
public MainForm()
{
InitializeComponent();
_inputImage = Bitmap.FromFile(@"E:\cracked.png") as Bitmap;
this.inputImagePictureBox.Image = _inputImage;
}
#endregion
#region Mouse Up and Down
Point _startPoint = Point.Empty;
private void left_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
_startPoint = e.Location;
Circle tempCircle = new Circle(_startPoint, 10);
Bitmap tempImage = (Bitmap)_inputImage.Clone();
Graphics g = Graphics.FromImage(tempImage);
tempCircle.Draw(g);
inputImagePictureBox.Image = tempImage;
}
}
private void pressed_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
if (_startPoint != e.Location)
{
Line tempLine = new Line(_startPoint, e.Location);
Bitmap tempImage = (Bitmap)_inputImage.Clone();
Graphics g = Graphics.FromImage(tempImage);
tempLine.Draw(g);
inputImagePictureBox.Image = tempImage;
}
}
}
Bitmap _savedImage;
private void left__MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
if (_startPoint != e.Location)
{
Line tempLine = new Line(_startPoint, e.Location);
Bitmap tempImage = (Bitmap)_inputImage.Clone();
Graphics g = Graphics.FromImage(tempImage);
tempLine.Draw(g);
_savedImage = tempImage;
inputImagePictureBox.Image = tempImage;
}
else
{
Bitmap tempImage = (Bitmap)_inputImage.Clone();
Graphics g = Graphics.FromImage(tempImage);
inputImagePictureBox.Image = tempImage;
}
}
}
}
【问题讨论】:
-
可以限制裁剪区域和缩放图形对象..
标签: c# winforms bitmap picturebox