1

嗨 frnds 任何人都可以帮我解决这个问题,因为我是 .net 世界的新手。下面的代码在本地服务器上运行良好,但是每当我尝试在服务器上上传时,它就会
得到

“GDI+ 中出现一般错误。”

if (FileUpload2.PostedFile.ContentType == "image/pjpeg" || FileUpload2.PostedFile.ContentType == "image/jpg" || FileUpload2.PostedFile.ContentType == "image/gif" || FileUpload2.PostedFile.ContentType == "image/jpeg" || FileUpload2.PostedFile.ContentType == "image/png")
            {

            string filename = FileUpload2.FileName;


            // Specify a upload directory
            string directory = Server.MapPath(@"datalistimg\");


            // Create a bitmap in memory of the content of the fileUpload control
            Bitmap originalBMP = new Bitmap(FileUpload2.FileContent);


            // Calculate the new image dimensions
            int origWidth = originalBMP.Width;
            int origHeight = originalBMP.Height;
            int sngRatio = origWidth / origHeight;
            int newWidth = 218;
            int newHeight = (newWidth * origHeight) / origWidth;


            // Create a new bitmap which will hold the previous resized bitmap
            Bitmap newBMP = new Bitmap(originalBMP, newWidth, newHeight);


            // Create a graphic based on the new bitmap
            Graphics oGraphics = Graphics.FromImage(newBMP);


            // Set the properties for the new graphic file
            oGraphics.SmoothingMode = SmoothingMode.AntiAlias;
            oGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;


            // Draw the new graphic based on the resized bitmap
            oGraphics.DrawImage(originalBMP, 0, 0, newWidth, newHeight);


            // Save the new graphic file to the server
            newBMP.Save(directory + filename);
            dfn2 = @"datalistimg/" + filename;


            originalBMP = null;
            newBMP = null;
            oGraphics = null;



            fn2 = System.IO.Path.GetFileName(FileUpload2.PostedFile.FileName);
            string SaveLocation = Server.MapPath("event") + "\\" + fn2;
            fn2 = "event/" + fn2;
            FileUpload2.PostedFile.SaveAs(SaveLocation);
4

0 回答 0