我在数据库中拿出了多张图要显示在picimage(picturebox控件)上,在图上点一下在此位置画出十字架,再别的地方点又多了个十字架,我想把第一次的十字架清掉怎么处理。
private void DrawCross()
{
try
{ Bitmap bitmap = new Bitmap(picimage.image.Width, picimage.image.Height , System.Drawing.Imaging.PixelFormat.Format24bppRgb);
Graphics graphics = Graphics.FromImage(bitmap);
int colorTransparence=100;
Pen opqPen = new Pen(Color.FromArgb(colorTransparence, Color.White), 3);
graphics.DrawImage(picimage.image, 0, 0, bitmap.Width, bitmap.Height);
graphics.DrawLine(opqPen, 0, msDownPtY, bitmap.Width - 1, msDownPtY);
graphics.DrawLine(opqPen, msDownPtX, 0, msDownPtX, bitmap.Height - 1); picImage.Image = bitmap;
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.ToString());
}
}
private void DrawCross()
{
try
{ Bitmap bitmap = new Bitmap(picimage.image.Width, picimage.image.Height , System.Drawing.Imaging.PixelFormat.Format24bppRgb);
Graphics graphics = Graphics.FromImage(bitmap);
int colorTransparence=100;
Pen opqPen = new Pen(Color.FromArgb(colorTransparence, Color.White), 3);
graphics.DrawImage(picimage.image, 0, 0, bitmap.Width, bitmap.Height);
graphics.DrawLine(opqPen, 0, msDownPtY, bitmap.Width - 1, msDownPtY);
graphics.DrawLine(opqPen, msDownPtX, 0, msDownPtX, bitmap.Height - 1); picImage.Image = bitmap;
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.ToString());
}
}
namespace WindowsFormsApplication10
{
public partial class Form1 : Form
{
Bitmap OrgBmp = null;
Bitmap CacheBmp = null;
public Form1()
{
InitializeComponent(); pictureBox1.Image = new Bitmap(400, 400);
pictureBox1.Size = new Size(400, 400);
Graphics g = Graphics.FromImage(pictureBox1.Image);
g.FillEllipse(new SolidBrush(Color.Red), new Rectangle(0, 0, 400, 400));
g.Dispose();
OrgBmp = new Bitmap(pictureBox1.Image);
} private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
CacheBmp = new Bitmap(OrgBmp);
Graphics g = Graphics.FromImage(CacheBmp);
g.FillRectangle(new SolidBrush(Color.Black), new Rectangle(e.Location, new Size(30, 30)));
g.Dispose();
pictureBox1.Image = CacheBmp;
}
}
}
this.picImage.Image = (Image)origalImage.Clone();//origalImage这个是数据库第一条记录
Bitmap bitmap = new Bitmap(picimage.image.Width,picimage.image.Height ,System.Drawing.Imaging.PixelFormat.Format24bppRgb);
Graphics graphics = Graphics.FromImage(bitmap);
重新赋值this.picImage.Image = (Image)origalImage.Clone();//origalImage 数据库第N条记录
{
try
{
if (i == 0)
{
MessageBox.Show("这已经是第一张图片!"); }
else
{
i--;
string path = queryimgtable.Rows[i]["Wafer_Image_Path"].ToString();
//this.picImage.Image = Image.FromFile(path);
Image tempImg = Image.FromFile(path);
this.picImage.Image = (Image)tempImg.Clone();
origiImage = (Image)tempImg.Clone();
tempImg.Dispose();
}
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.ToString());
} } private void btnNext_Click(object sender, EventArgs e)
{
try
{
if (i < queryimgtable.Rows.Count - 1)
{
i++;
string path = queryimgtable.Rows[i]["Wafer_Image_Path"].ToString();
Image tempImg = Image.FromFile(path);
this.picImage.Image = (Image)tempImg.Clone();
origiImage = (Image)tempImg.Clone();
tempImg.Dispose();
}
else
{
MessageBox.Show("这已经是最后一张图片!");
}
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.ToString());
}
}
我在两个按钮加了如上类容实现了
if (System.IO.File.Exists(path))
{
this.picImage.Image = Image.FromFile(path);
origiImage = (Image)this.picImage.Image.Clone();
i = 0;//i记录当前位置
}
还得多思考啊 谢谢各位