troubleshooting Question

Image resize

Avatar of virafh
virafh asked on
.NET ProgrammingASP.NET
9 Comments2 Solutions451 ViewsLast Modified:
Image is resizing in development VS 2008 but when publishing web site on iis and try to upload a same only scanned file which is uploade in development environment giving an error
System.ArgumentException: Parameter is not valid. at System.Drawing.Bitmap..ctor(String filename)
private Bitmap ResizeImage(Bitmap mg, Size newSize)
    {
        double ratio = 0d;
        double myThumbWidth = 0d;
        double myThumbHeight = 0d;
        int x = 0;
        int y = 0;
        Bitmap bp;
        if ((mg.Width / Convert.ToDouble(newSize.Width)) > (mg.Height /
        Convert.ToDouble(newSize.Height)))
            ratio = Convert.ToDouble(mg.Width) / Convert.ToDouble(newSize.Width);
        else
            ratio = Convert.ToDouble(mg.Height) / Convert.ToDouble(newSize.Height);
        myThumbHeight = Math.Ceiling(mg.Height / ratio);
        myThumbWidth = Math.Ceiling(mg.Width / ratio);
 
        Size thumbSize = new Size((int)myThumbWidth, (int)myThumbHeight);
        bp = new Bitmap(newSize.Width, newSize.Height);
        x = (newSize.Width - thumbSize.Width) / 2;
        y = (newSize.Height - thumbSize.Height);
        // Had to add System.Drawing class in front of Graphics ---
        System.Drawing.Graphics g = Graphics.FromImage(bp);
        g.SmoothingMode = SmoothingMode.HighQuality;
        g.InterpolationMode = InterpolationMode.HighQualityBicubic;
        g.PixelOffsetMode = PixelOffsetMode.HighQuality;
        Rectangle rect = new Rectangle(x, y, thumbSize.Width, thumbSize.Height);
        g.DrawImage(mg, rect, 0, 0, mg.Width, mg.Height, GraphicsUnit.Pixel);
        g.Dispose();
        return bp;
    }
 
calling of function
 
 
Bitmap mg = new Bitmap(HIF.PostedFile.FileName);
                    Size newSize = new Size(0,0);
                    if (mg.Width == 1755 && mg.Height == 1242)
                    {
                        newSize = new Size(1200, 850);
                        Bitmap bp = ResizeImage(mg, newSize);
                        String path = diClubName + "\\" + fn;
                        bp.Save(path , System.Drawing.Imaging.ImageFormat.Jpeg);
                        bp.Dispose();
                    }
ASKER CERTIFIED SOLUTION
virafh

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros