C#中pictureBox鼠标拖动图片如何保存图片的拖动后的位置
代码:boolwselected=false;boolmouseflag=false;Pointp=newPoint();privatevoidpbHeadPicture...
代码: bool wselected = false;
bool mouseflag = false;
Point p = new Point();
private void pbHeadPicture_MouseDown(object sender, MouseEventArgs e)
{
pbHeadPicture.Cursor = Cursors.Hand;
mouseflag = true;
wselected = true;
p.X = e.X;
p.Y = e.Y;
}
int driftX = 0, driftY = 0;
int mx = 0, my = 0;
Bitmap bm;
private void pbHeadPicture_MouseMove(object sender, MouseEventArgs e)
{
if (wselected)
{
driftX = p.X - e.X;
driftY = p.Y - e.Y;
mx = mx - driftX;
my = my - driftY;
bm = new Bitmap(pbHeadPicture.Image);
Graphics g = pbHeadPicture.CreateGraphics();
g.Clear(pbHeadPicture.BackColor);
g.DrawImage(bm, mx, my);
p.X = e.X;
p.Y = e.Y;
}
}
private void pbHeadPicture_MouseUp(object sender, MouseEventArgs e)
{
pbHeadPicture.Cursor = Cursors.Default;
wselected = false;
}
想把图片保存, 但是bm还是原图 展开
bool mouseflag = false;
Point p = new Point();
private void pbHeadPicture_MouseDown(object sender, MouseEventArgs e)
{
pbHeadPicture.Cursor = Cursors.Hand;
mouseflag = true;
wselected = true;
p.X = e.X;
p.Y = e.Y;
}
int driftX = 0, driftY = 0;
int mx = 0, my = 0;
Bitmap bm;
private void pbHeadPicture_MouseMove(object sender, MouseEventArgs e)
{
if (wselected)
{
driftX = p.X - e.X;
driftY = p.Y - e.Y;
mx = mx - driftX;
my = my - driftY;
bm = new Bitmap(pbHeadPicture.Image);
Graphics g = pbHeadPicture.CreateGraphics();
g.Clear(pbHeadPicture.BackColor);
g.DrawImage(bm, mx, my);
p.X = e.X;
p.Y = e.Y;
}
}
private void pbHeadPicture_MouseUp(object sender, MouseEventArgs e)
{
pbHeadPicture.Cursor = Cursors.Default;
wselected = false;
}
想把图片保存, 但是bm还是原图 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询