A Generic error occurred in GDI in Bitmap Save method

0 votes

I am trying to copy a thumbnail of an image to the thumbnail folder But when I do this I have this error: "A generic error occurred in GDI+". I followed this link to do that: http://weblogs.asp.net/markmcdonnell/archive/2008/03/09/resize-image-before-uploading-to-server.aspx.

Code:

    protected void ResizeAndSave(PropBannerImage objPropBannerImage)

    {

        // Create a bitmap of the content of the fileUpload control in memory

        Bitmap originalBMP = new Bitmap(fuImage.FileContent);


        // Calculate the new image dimensions

        int origWidth = originalBMP.Width;

        int origHeight = originalBMP.Height;

        int sngRatio = origWidth / origHeight;

        int thumbWidth = 100;

        int thumbHeight = thumbWidth / sngRatio;


        int bannerWidth = 100;

        int bannerHeight = bannerWidth / sngRatio;


        // Create a new bitmap which will hold the previous resized bitmap

        Bitmap thumbBMP = new Bitmap(originalBMP, thumbWidth, thumbHeight);

        Bitmap bannerBMP = new Bitmap(originalBMP, bannerWidth, bannerHeight);


        // Create a graphic based on the new bitmap

        Graphics oGraphics = Graphics.FromImage(thumbBMP);

        // 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, thumbWidth, thumbHeight);


        Bitmap newBitmap = new Bitmap(thumbBMP);

        thumbBMP.Dispose();

        thumbBMP = null;


        // Save the new graphic file to the server

        newBitmap.Save("~/image/thumbs/" + "t" + objPropBannerImage.ImageId, ImageFormat.Jpeg);


        oGraphics = Graphics.FromImage(bannerBMP);

        // 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, bannerWidth, bannerHeight);

        // Save the new graphic file to the server

        bannerBMP.Save("~/image/" + objPropBannerImage.ImageId + ".jpg");



        // Once finished with the bitmap objects, we deallocate them.

        originalBMP.Dispose();


        bannerBMP.Dispose();

        oGraphics.Dispose();

    }

Can someone help me solve this?

May 23 in Others by Kichu
• 19,040 points
48 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Others

0 votes
1 answer

Error cannot provide both a color and a decoration in Flutter container.

Hi@akhtar, The color and decoration arguments cannot both be supplied, since it ...READ MORE

answered Jul 29, 2020 in Others by MD
• 95,360 points
1,957 views
0 votes
1 answer
0 votes
1 answer

Using/Handling colon inside a JSF generated HTML element ID in CSS selector

Yes, you can.  Just Backslash (\) the colon.  Like ...READ MORE

answered Nov 14, 2018 in Others by DataKing99
• 8,240 points
1,652 views
0 votes
1 answer

Using unserialize in PHP throws the same error repeatedly

I googled 'Node no longer exists', and ...READ MORE

answered Nov 14, 2018 in Others by DataKing99
• 8,240 points
805 views
0 votes
1 answer

What is a name function in JavaScript & how to define it?

A named function declares a name as ...READ MORE

answered Mar 7, 2019 in Others by Frankie
• 9,830 points
781 views
0 votes
0 answers

No connection could be made because the target machine actively refused it?

 I was doing HttpWebRequest to a WebService ...READ MORE

May 5 in Others by Kichu
• 19,040 points
331 views
0 votes
1 answer

Which design pattern to use for pre-process process and post-process task

You have pre-defined and precise steps to ...READ MORE

answered Jun 9 in C# by rajiv
• 1,620 points
12 views
0 votes
3 answers

Trying to upload files using Selenium(C#)

You can try using Javascript Executor to ...READ MORE

answered Aug 23, 2019 in Selenium by Abha
• 28,100 points
4,468 views
0 votes
1 answer

Deploy my Windows 10 IOT core application locally!

Of course, you, can! That is, in ...READ MORE

answered Jul 17, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
499 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP