用C#制作电子相册的“添加图片”和“删除图片”的代码
1个回答
2013-11-13
展开全部
删除本地图片
首先获得图片的路径
string address="路径";
FileInfo file = new FileInfo(address);
file.delete();
增加就直接保存图片框里面的图片就OK了
SaveFileDialog fileone = new SaveFileDialog();
fileone.OverwritePrompt = true;
fileone.Filter = "BMP文件|*.bmp|GIF文件|*.gif|JPG文件|*.jpg|PNG文件|*.png|ICO文件|*.ico|所有文件|*.*";
fileone.FilterIndex = 1;
fileone.ShowDialog();
if (fileone.FilterIndex == 1)
{
this.picBox.Image.Save(fileone.FileName, System.Drawing.Imaging.ImageFormat.Bmp);
userHelper.iniSuffix = ".bmp";
}
else if (fileone.FilterIndex == 2)
{
this.picBox.Image.Save(fileone.FileName, System.Drawing.Imaging.ImageFormat.Gif);
userHelper.iniSuffix = ".gif";
}
else if (fileone.FilterIndex == 3)
{
this.picBox.Image.Save(fileone.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
userHelper.iniSuffix = ".jpg";
}
else if (fileone.FilterIndex == 4)
{
this.picBox.Image.Save(fileone.FileName, System.Drawing.Imaging.ImageFormat.Png);
userHelper.iniSuffix = ".png";
}
else
{
this.picBox.Image.Save(fileone.FileName, System.Drawing.Imaging.ImageFormat.Icon);
userHelper.iniSuffix = ".ico";
}
userHelper.iniAddress = fileone.FileName;
toolStripTextBox1.Text = fileone.FileName;
首先获得图片的路径
string address="路径";
FileInfo file = new FileInfo(address);
file.delete();
增加就直接保存图片框里面的图片就OK了
SaveFileDialog fileone = new SaveFileDialog();
fileone.OverwritePrompt = true;
fileone.Filter = "BMP文件|*.bmp|GIF文件|*.gif|JPG文件|*.jpg|PNG文件|*.png|ICO文件|*.ico|所有文件|*.*";
fileone.FilterIndex = 1;
fileone.ShowDialog();
if (fileone.FilterIndex == 1)
{
this.picBox.Image.Save(fileone.FileName, System.Drawing.Imaging.ImageFormat.Bmp);
userHelper.iniSuffix = ".bmp";
}
else if (fileone.FilterIndex == 2)
{
this.picBox.Image.Save(fileone.FileName, System.Drawing.Imaging.ImageFormat.Gif);
userHelper.iniSuffix = ".gif";
}
else if (fileone.FilterIndex == 3)
{
this.picBox.Image.Save(fileone.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
userHelper.iniSuffix = ".jpg";
}
else if (fileone.FilterIndex == 4)
{
this.picBox.Image.Save(fileone.FileName, System.Drawing.Imaging.ImageFormat.Png);
userHelper.iniSuffix = ".png";
}
else
{
this.picBox.Image.Save(fileone.FileName, System.Drawing.Imaging.ImageFormat.Icon);
userHelper.iniSuffix = ".ico";
}
userHelper.iniAddress = fileone.FileName;
toolStripTextBox1.Text = fileone.FileName;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询