110,534
社区成员
发帖
与我相关
我的任务
分享
Bitmap image1;
private void Button1_Click(System.Object sender, System.EventArgs e)
{
try
{
// Retrieve the image.
image1 = new Bitmap(@"C:\Documents and Settings\All Users\"
+ @"Documents\My Music\music.bmp", true);
int x, y;
// Loop through the images pixels to reset color.
for(x=0; x<image1.Width; x++)
{
for(y=0; y<image1.Height; y++)
{
Color pixelColor = image1.GetPixel(x, y);
Color newColor = Color.FromArgb(pixelColor.R, 0, 0);
image1.SetPixel(x, y, newColor);
}
}
// Set the PictureBox to display the image.
PictureBox1.Image = image1;
// Display the pixel format in Label1.
Label1.Text = "Pixel format: "+image1.PixelFormat.ToString();
}
catch(ArgumentException)
{
MessageBox.Show("There was an error." +
"Check the path to the image file.");
}
}
private void Button5_Click(System.Object sender, System.EventArgs e)
{
try
{
if (image1 != null)
{
image1.Save("c:\\myBitmap.bmp");
Button5.Text = "Saved file.";
}
}
catch(Exception)
{
MessageBox.Show("There was a problem saving the file." +
"Check the file permissions.");
}
}
Bitmap image1;
private void Button1_Click(System.Object sender, System.EventArgs e)
{
try
{
// Retrieve the image.
image1 = new Bitmap(@"C:\Documents and Settings\All Users\"
+ @"Documents\My Music\music.bmp", true);
int x, y;
// Loop through the images pixels to reset color.
for(x=0; x<image1.Width; x++)
{
for(y=0; y<image1.Height; y++)
{
Color pixelColor = image1.GetPixel(x, y);
Color newColor = Color.FromArgb(pixelColor.R, 0, 0);
image1.SetPixel(x, y, newColor);
}
}
// Set the PictureBox to display the image.
PictureBox1.Image = image1;
// Display the pixel format in Label1.
Label1.Text = "Pixel format: "+image1.PixelFormat.ToString();
}
catch(ArgumentException)
{
MessageBox.Show("There was an error." +
"Check the path to the image file.");
}
}
private void Button5_Click(System.Object sender, System.EventArgs e)
{
try
{
if (image1 != null)
{
image1.Save("c:\\myBitmap.bmp");
Button5.Text = "Saved file.";
}
}
catch(Exception)
{
MessageBox.Show("There was a problem saving the file." +
"Check the file permissions.");
}
}
Image image = Image.FromFile("图片文件全路径");
image.Save("保存全路径", System.Drawing.Imaging.ImageFormat.Bmp);//第二个参数是保存格式,根据自己需要修改