这个方法是我参考别人的代码写的bmp类型的图片转为gif 可是转换之后图片的后缀还是bmp 请大家帮我看看! 谢谢!// x_imgPath这个是获得的图片路径
//GifPath这个是转换后保存的路径public void UpBmptojpg(string x_imgPath, string GifPath)
{ System.IO.FileStream stream;
stream = File.OpenRead(x_imgPath);
Bitmap bmp = new Bitmap(stream);
System.Drawing.Image image = bmp;
System.Drawing.Image newImage = image.GetThumbnailImage(bmp.Width, bmp.Height, null, new IntPtr());
Graphics g = Graphics.FromImage(newImage);
g.DrawImage(newImage, 0, 0, newImage.Width, newImage.Height); //将原图画到指定的图上
g.Dispose();
stream.Close();
newImage.Save(GifPath, ImageFormat.Gif);
}
}
是不是你保存的时候参数GifPath带有.bmp后缀呀?
{
HttpFileCollection files = HttpContext.Current.Request.Files;
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile PostedFile = files[i]; if (files[i].FileName == "")
{
Response.Write("<script>alert('你选择的選擇相片"+(i+1)+"不能为空!')</script>");
return;
}
else
{
string Filename = PostedFile.FileName;
string type = Filename.Substring(Filename.LastIndexOf('.'), Filename.Length - PostedFile.FileName.LastIndexOf('.'));
string serverpath = Server.MapPath("~/Uploads/Company/ERIC/ImageFiles/") + s + type;
if (type == ".bmp")
{
UpBmptojpg(Filename, serverpath);
}
if (type == ".jpg" || type == ".gif")
{
if (PostedFile.ContentLength < 10000)
{
string x_about = Request.Params["x_about" + (i + 1)];
string Img1 = "Uploads/Company/ERIC/ImageFiles/" + s + type;
PostedFile.SaveAs(serverpath);
int j = b.Insertphotos(X_id, s, x_about, Img1);
}
else
{
Response.Write("<script>alert('你选择的上传图片过大!请重新选择')</script>");
return;
}
}
else
{
Response.Write("<script>alert('你选择的上传图片类型不对!请重新选择')</script>");
return;
} }
}
Response.Write("<script>var isRe=confirm('上传成功!是否继续上传到《" + X_name + "》相册');if(isRe){location.href=location.href;}else{location.href='photob_list2.aspx'}</script>");
}
public void UpBmptojpg(string x_imgPath, string GifPath)
{ System.IO.FileStream stream;
stream = File.OpenRead(x_imgPath);
Bitmap bmp = new Bitmap(stream);
System.Drawing.Image image = bmp;
System.Drawing.Image newImage = image.GetThumbnailImage(bmp.Width, bmp.Height, null, new IntPtr());
Graphics g = Graphics.FromImage(newImage);
g.DrawImage(newImage, 0, 0, newImage.Width, newImage.Height); //将原图画到指定的图上
g.Dispose();
stream.Close();
newImage.Save(GifPath, ImageFormat.Gif);
}