可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
string ServerUploadFolder = HttpContext.Current.Server.MapPath("~/Uploads/" + value.PhysicalFileName); MultipartFormDataStreamProvider streamProvider = new MultipartFormDataStreamProvider(ServerUploadFolder); Image img = Image.FromFile(ServerUploadFolder); var bmp = new Bitmap(img.Width, img.Height); using (Graphics gfx = Graphics.FromImage(bmp)) { gfx.Clear(Color.White); gfx.DrawImage(img, 0, 0, img.Width, img.Height); } bmp.RotateFlip(RotateFlipType.Rotate90FlipNone); string imagePath = value.FileUrl.Replace(Path.GetFileName(value.FileUrl), Path.GetFileName(value.FileUrl)); bmp.Save(imagePath,img.RawFormat);
In this Save Method There are Problem Occured GDI+ Error . I Have Tried Many Solutions but that is not worked. I am rotate image with 90's degree and after it is rotate it is save in database.
回答1:
In may case the image file already exists in system drive, so app throws the error "A Generic error occured in GDI+".
- Verify that the folder must already exist where image is to be saved.
- Verify that the file must not exist in the path with the same name.
回答2:
The GDI+ error you're receiving is generic and could refer to any one of a number of different issues. Try the following and see how you get on:
If your image is based on a stream, ensure that it is still open when you do the Save operation. Also, make sure permissions are correct on the destination folder, i.e. that Write permission is enabled.
Finally, here's some example code which worked for me:
// Path to source file string inputPath = Server.MapPath(@"~\Content\somefile.jpg"); // Create an image from the file using (Image img = Bitmap.FromFile(inputPath)) { // Rotate the image 90 degrees img.RotateFlip(RotateFlipType.Rotate90FlipNone); // Path to destination file string outputPath = Server.MapPath(@"~\Content\rotated" + System.IO.Path.GetExtension(inputPath)); // Delete the destination file if it already exists if (System.IO.File.Exists(outputPath)) { System.IO.File.Delete(outputPath); } // Save the rotated image in the same ImageFormat as the source img.Save(outputPath, img.RawFormat); }