C#下用DrawImage将图像绘制到picturebox上
我用picturebox打开了一张图片,利用代码openFileDialog1=newOpenFileDialog();openFileDialog1.Filter="j...
我用picturebox打开了一张图片,利用代码
openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "jpg文件(*.jpg)|*.jpg|jpeg文件(*.jpeg)|*.jpeg|bmp文件(*.bmp)|*.bmp|gif文件(*.gif)|*.gif|ico文件(*.ico)|*.ico|png文件(*.png)|*.png|tif(文件)(*.tif)|*.tif|wmf文件(*.wmf)|*.wmf";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
this.pictureBox1.Image = System.Drawing.Image.FromFile(openFileDialog1.FileName);
str = openFileDialog1.FileName;
this.保存ToolStripMenuItem.Visible = true;
toolStripStatusLabel1.Text = "图片路径:" + str;
}
现在我对图片进行了反色编辑
private void 反色ToolStripMenuItem_Click(object sender, EventArgs e)
{
int Height = image.Height;
int Width = image.Width;
Bitmap bitmap = new Bitmap(Width ,Height );
Bitmap MyBitmap = (Bitmap)image;
Color pixel;
for (int x = 1; x < Width; x++)
{
for (int y = 1; y < Height ; y++)
{
int r, g1, b;
pixel = MyBitmap.GetPixel(x, y);
r = 255 - pixel.R;
g1 = 255 - pixel.G;
b = 255 - pixel.B;
bitmap.SetPixel(x, y, Color.FromArgb(r, g1, b));
}
}
g = this.CreateGraphics ();
g.DrawImage(bitmap ,0,0);
}
执行后,图像只能在picturebox外显示,请问如何才能覆盖原图片显示处理后的图片 ? 展开
openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "jpg文件(*.jpg)|*.jpg|jpeg文件(*.jpeg)|*.jpeg|bmp文件(*.bmp)|*.bmp|gif文件(*.gif)|*.gif|ico文件(*.ico)|*.ico|png文件(*.png)|*.png|tif(文件)(*.tif)|*.tif|wmf文件(*.wmf)|*.wmf";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
this.pictureBox1.Image = System.Drawing.Image.FromFile(openFileDialog1.FileName);
str = openFileDialog1.FileName;
this.保存ToolStripMenuItem.Visible = true;
toolStripStatusLabel1.Text = "图片路径:" + str;
}
现在我对图片进行了反色编辑
private void 反色ToolStripMenuItem_Click(object sender, EventArgs e)
{
int Height = image.Height;
int Width = image.Width;
Bitmap bitmap = new Bitmap(Width ,Height );
Bitmap MyBitmap = (Bitmap)image;
Color pixel;
for (int x = 1; x < Width; x++)
{
for (int y = 1; y < Height ; y++)
{
int r, g1, b;
pixel = MyBitmap.GetPixel(x, y);
r = 255 - pixel.R;
g1 = 255 - pixel.G;
b = 255 - pixel.B;
bitmap.SetPixel(x, y, Color.FromArgb(r, g1, b));
}
}
g = this.CreateGraphics ();
g.DrawImage(bitmap ,0,0);
}
执行后,图像只能在picturebox外显示,请问如何才能覆盖原图片显示处理后的图片 ? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询