本文介绍了使用C Sharp .net在Picturebox图像上绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个图片框,在其上加载图像后,我使用绘图对象绘制了一些线条和矩形,并在运行时添加了一些控件.
但是在打印或保存dat图像时,它仅保存dat图像,没有任何线条或矩形...
请帮助如何保存图纸零件
我的加载图片代码如下:
i have a picturebox, after loading image on that i''m drwaing some lines and rectangle using drawing objects, also adding some controls at runtime.
but during printing or saving dat image it saves only dat image without any lines or rectangle...
pl help how to save with drawing part
my load image code is like:
private void loadImageToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
OpenFileDialog open = new OpenFileDialog();
open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
if (open.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image = new Bitmap(open.FileName);
trackBar1.Value = pictureBox1.Height;
trackBar2.Value = pictureBox1.Height;
}
}
catch (ApplicationException ex)
{
MessageBox.Show(ex.Message.ToString());
}
trackBar1.Enabled = true;
trackBar2.Enabled = true;
pictureBox1.Enabled = true;
lineToolStripMenuItem.Enabled = false;
}
//code for creating drawing
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
Graphics g = null;
g = Graphics.FromImage(pictureBox1.Image);
g = pictureBox1.CreateGraphics();
g.DrawLine(Pens.Red, 0, Convert.ToInt32(trackBar1.Maximum) - trackBar1.Value, Convert.ToInt32(pictureBox1.Width), Convert.ToInt32(trackBar1.Maximum) - trackBar1.Value);
g.DrawLine(Pens.Blue, 0, Convert.ToInt32(trackBar2.Maximum) - trackBar2.Value, Convert.ToInt32(pictureBox1.Width), Convert.ToInt32(trackBar2.Maximum) - trackBar2.Value);
g.Dispose();
mouseMovePt = e.Location;
}
// code for saving image
private void saveImageToolStripMenuItem_Click_1(object sender, EventArgs e)
{
SaveFileDialog savefile = new SaveFileDialog();
savefile.DefaultExt = "jpeg";
savefile.Filter = "All files*.*|*.*";
if (savefile.ShowDialog() == DialogResult.OK)
{
int width = pictureBox1.Width;
int height = pictureBox1.Height;
Bitmap bitmap = new Bitmap(width, height);
Rectangle rc = new Rectangle(0, 0, width, height);
pictureBox1.DrawToBitmap(bitmap, rc);
bitmap.Save(savefile.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
thnxxxxxxx
thnxxxxxxx
推荐答案
这篇关于使用C Sharp .net在Picturebox图像上绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!