[C#.NET] Is there more efficient code to download, crop and save and image?

Soldato
Joined
12 Jun 2005
Posts
5,361
As title really.

Here is the code I created:

Code:
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("imagestr");
            HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();

            Image image = Image.FromStream(webResponse.GetResponseStream());

            Bitmap bmp = new Bitmap(350, image.Height - 3);
            Rectangle rect = new Rectangle(74, 1, 350, image.Height - 3);
            Graphics g = Graphics.FromImage(bmp);
            g.DrawImage(image, 0, 0, rect, GraphicsUnit.Pixel);

            bmp.Save("bmp.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

Is there a better way of doing it/can you see anything that could be wrong with the code?
 
Looks pretty good to me. You could also look into cutting rectangles out of the image. I created a tool that loads and image and then cuts rectangles out of the areas that aren't needed. Something to think about, i could post code if you wanted to go down this route.
 
Back
Top Bottom