مرجع تخصصی برنامه نویسان

انجمن تخصصی برنامه نویسان فارسی زبان

کاربر سایت

اوبالیت

عضویت از 1392/08/24

resize عکس و خطای A generic error occurred in GDI+.

  • پنجشنبه 31 فروردین 1396
  • 20:30
تشکر میکنم
                      


                        int newWidthIn = 160;
                        int newHeightIn = 200;

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

                        // Calculate the new image dimensions
                        int origWidth = originalBMP.Width;
                        int origHeight = originalBMP.Height;
                        float sngRatio = 1;
                        int newWidth = 0;
                        int newHeight = 0;

                        if (origWidth > newWidthIn || origHeight > newHeightIn)
                        {
                            if (origWidth > origHeight)
                            {
                                sngRatio = (float)origWidth / (float)origHeight;
                                newWidth = newWidthIn;
                                newHeight = Convert.ToInt32(newWidthIn / sngRatio);
                            }
                            else if (origWidth < origHeight)
                            {
                                sngRatio = (float)origHeight / (float)origWidth;
                                newHeight = newHeightIn;
                                newWidth = Convert.ToInt32(newHeightIn / sngRatio);
                            }
                            else
                            {
                                if (origWidth > newWidthIn)
                                {
                                    sngRatio = (float)origWidth / (float)newWidthIn;
                                    newWidth = newWidthIn;
                                    newHeight = Convert.ToInt32(origHeight / sngRatio);
                                }
                                else if (origHeight > newHeightIn)
                                {
                                    sngRatio = (float)origHeight / (float)newHeightIn;
                                    newHeight = newHeightIn;
                                    newWidth = Convert.ToInt32(origWidth / sngRatio);
                                }
                            }

                            // 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 resize Image ------------- //
                            newBMP.Save(FilePath);

                            // Once finished with the bitmap objects, we deallocate them.
                            originalBMP.Dispose();
                            newBMP.Dispose();
                            oGraphics.Dispose();
                        }
                        else
                        {
                            fuPicture.SaveAs(Server.MapPath(FilePath));
                        }

سلام وقت بخیر من می خوام عکس رو resize کنم اما با این خطا مواجه میشم:

A generic error occurred in GDI+.

پاسخ های این پرسش

تعداد پاسخ ها : 2 پاسخ
کاربر سایت

ایمان مدائنی

عضویت از 1392/01/20

  • جمعه 1 اردیبهشت 1396
  • 20:06

این لینک رو ببینید

کاربر سایت

sinacoantom

عضویت از 1399/01/04

  • چهارشنبه 17 اردیبهشت 1399
  • 16:29

سلام استاد منم همین مشکل رو دارم کد هایی که نوشتم همون کدی هست که خودتون گفتید اما باز هم خطا میده لطفا ببیشتر توضیح بدین

ممنون

کاربرانی که از این پست تشکر کرده اند

هیچ کاربری تا کنون از این پست تشکر نکرده است

اگر نیاز به یک مشاور در زمینه طراحی سایت ، برنامه نویسی و بازاریابی الکترونیکی دارید

با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)