Click here to Skip to main content
15,900,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I want re-size one image into Multiple size Images like thumb_image(Width 48px height 64px),Small_image(Width 240px height 320px),big_image(Width 1080px high 1440px). I am uploading image using File Upload in asp.net c#. on Submit button I want to create above size image dynamically & save in my specific folder.

Please provide me help or sample code for the same..

Thanks Advance
Posted

int NewWidth = 100;
        int NewHeight = 74;
        // FileStream fs = File.Open(, FileMode.Open);
        StreamReader sr = new StreamReader(HttpContext.Current.Server.MapPath(path) + guid + "." + fileName.Split('.')[fileName.Split('.').Length - 1]);
        System.Drawing.Bitmap bmpOut = new System.Drawing.Bitmap(NewWidth, NewHeight);
        System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmpOut);
        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
        g.FillRectangle(System.Drawing.Brushes.White, 0, 0, NewWidth, NewHeight);
        g.DrawImage(new System.Drawing.Bitmap(sr.BaseStream), 0, 0, NewWidth, NewHeight);
        MemoryStream stream = new MemoryStream();

        bmpOut.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);

        String saveImagePath = path + guid + "_thumbnail.jpg";
        bmpOut.Save(HttpContext.Current.Server.MapPath(saveImagePath), System.Drawing.Imaging.ImageFormat.Jpeg);
        g.Dispose();
        bmpOut.Dispose();
        sr.Dispose();

image geneation
 
Share this answer
 
v2
Comments
Govind_sk 7-Mar-13 6:58am    
@taha but I want multiple Images with diffrent width & Height.
Please look at the codes in the following sites: Link 1[^]
Link 2[^]
Link 3[^]
In your upload control call these methods for different ratios for your images.

Good luck,
OI
 
Share this answer
 
v2
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900