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, 2022 in Others by Kichu
• 19,040 points
1,640 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,460 points
5,625 views
0 votes
1 answer

"The underlying connection was closed: An unexpected error occurred on a send." With SSL Certificate

The solution for this for me was ...READ MORE

answered Feb 18, 2022 in Others by Rahul
• 9,680 points
11,404 views
0 votes
1 answer

How to get rid of a #value error in Excel?

Changing the format to "Number" doesn't actually ...READ MORE

answered Oct 3, 2022 in Others by narikkadan
• 63,600 points
788 views
0 votes
1 answer

How to fix a circular reference error by if condition in excel file?

Circular reference in this context refers to ...READ MORE

answered Nov 21, 2022 in Others by narikkadan
• 63,600 points
720 views
0 votes
1 answer

How to save a new sheet in an existing excel file, using Pandas?

import pandas as pd import numpy as np path ...READ MORE

answered Dec 10, 2022 in Others by narikkadan
• 63,600 points
7,522 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, 2022 in Others by Kichu
• 19,040 points
2,805 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, 2022 in C# by rajiv
• 1,620 points
1,801 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,140 points
5,716 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
1,110 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP