Как нарисовать увеличенное изображение?
У меня есть картинкаSize
400х400 в моем приложении.SizeMode
из Picturebox установлен наZoomed
, Я загрузил PNG-изображение 700X446 в картинке.
У меня есть следующая проблема,
Даже если я рисую черную прямую линию вдоль красной дорожки, на самом деле она отображается вдоль загруженного изображения из перспективы.
Как я могу решить проблему?
Постскриптум Я хочу рисовать только на изображении, а не на всей картинке.
Исходный код:
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;
}
}
}
}