Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8167849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:19:56+00:00 2026-06-06T20:19:56+00:00

i have following coding to resize image and than save it my virtual folder

  • 0

i have following coding to resize image and than save it my virtual folder “vicpic/scimages”

  if (FileUpload5.PostedFile != null)
    {
        if (FileUpload5.PostedFile.ContentLength > (1024 * 1024))
        {
            Label4.Text = "Upload status: The file has to be less than 1 MB. Please resize your photo and than upload it again.";
        }
        else
        {
            System.Drawing.Image imageToBeResized = System.Drawing.Image.FromStream(FileUpload5.PostedFile.InputStream);
            int imageHeight = imageToBeResized.Height;
            int imageWidth = imageToBeResized.Width;
            int maxHeight = 660;
            int maxWidth = 560;
            imageHeight = (imageHeight * maxWidth) / imageWidth;
            imageWidth = maxWidth;
            if (imageHeight > maxHeight)
            {
                imageWidth = (imageWidth * maxHeight) / imageHeight;
                imageHeight = maxHeight;
            }
            Bitmap bitmap = new Bitmap(imageToBeResized, imageWidth, imageHeight);
            System.IO.MemoryStream stream = new MemoryStream();
            // bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
            stream.Position = 0;
            byte[] image = new byte[stream.Length + 1];
            stream.Read(image, 0, image.Length);

            string FileName = Path.GetFileName(FileUpload5.PostedFile.FileName);
            //Save files to disk
            string extension = Path.GetExtension(FileUpload5.PostedFile.FileName);
            //Path.Combine(Server.MapPath("~/vicpic/scimages"), imageName);
            string imagename = DropDownList2.SelectedItem.Text + "4" + extension;


            bitmap.Save(Server.MapPath("~/vicpic/scimages/") + imagename);

            bitmap.Dispose();
            imageToBeResized.Dispose();
            GC.Collect();



            try
            {
                con.Open();
                cmd.ExecuteNonQuery();
            }

            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }

            finally
            {
                con.Close();
                con.Dispose();
                Label4.Text = "Upload status:Successfully.";

            }
        }

    }

but it shows A generic error occurred in GDI+

can anyone suggest where the problem is?

i want to save image in “vicpic/scimages” folder on my host server. it is virtual directory and i also have granted all the permission required for the directory.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T20:19:57+00:00Added an answer on June 6, 2026 at 8:19 pm

    I had the same issue. It appears that the memory stream that the object was created on has to be open at the time the object is saved. Not to duplicate code and text just take a look at this Q & A: A generic error occurred in GDI+, JPEG Image to MemoryStream

    So instead of bitmap.Save(Server.MapPath("~/vicpic/scimages/") + imagename); your code could look like this:

    using (var m = new MemoryStream())
    {
           bitmap.Save(m, ImageFormat.Jpeg);
           var img = Image.FromStream(m);
           img.Save(Server.MapPath("~/vicpic/scimages/") + imagename);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following UML class diagram and java coding for each, please tell me
i have a splash screen at start up. with the following coding public class
I have created the following database layout, and started coding the application. The more
I have seen lot projects following this kind of coding style Any significant advantage
I have the following coding: <div class=product-top-icons> <div class=energy-rating-1><img src=http://www.justhome.co/skin/frontend/default/just2011/images/assets/<?php echo $_product->getAttributeText('energy_rating_one');?>.jpg></div> <div class=energy-rating-2><img
I have the following coding for a button. My problem is that the Query
I'm new to PL/SQL coding and I have the following question: I have table
I have following coding in my ViewDidLoad of ViewController - (void)viewDidLoad { [super viewDidLoad];
I just discovered zen-coding. I have the following snippet of code I want to
I'm coding in PHP/MySQL and have the following query to fetch products and product

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.