Resizing an image with c# -


resizing image file in c#, wich common used @ least (bmp, jpg etc etc.)

i found many snippets not complete one. i'm gonna ask again comes here might use complete file:

this outputs file same width , height.

using system; using system.drawing; using system.drawing.drawing2d;  namespace picresize {     class program     {         static void main(string[] args)         {             resizeimage(0, 0, 200, 200);         }          public static void resizeimage(int x1, int y1, int width, int height)         {              string filename = @"c:\testimage.jpg";             using (image image = image.fromfile(filename))             {                 using (graphics graphic = graphics.fromimage(image))                 {                     // crop , resize image.                     rectangle destination = new rectangle(0, 0, width, height);                     graphic.drawimage(image, destination, x1, y1, width, height, graphicsunit.pixel);                 }                 image.save(@"c:\testimagea.jpg");             }         }     } } 

so, since there no examples around, how works? need fix here?

thanks

you can this:

        public void resizeimage(string filename, int width, int height)         {             using (image image = image.fromfile(filename))             {                 new bitmap(image, width, height).save(filename);             }         } 

if new file replace or custom path of choosing:

new bitmap(image, width, height).save(filename.insert(filename.lastindexof('.'),"a")); 

Comments