How to crop an image in c#

This works:


using (Image FullsizeImage = Image.FromFile(sourceFilePath))
        {
            using (Bitmap NewImage = new Bitmap(FullsizeImage.Width, ThumbHeight))
            {
                using (Graphics newgraphics = Graphics.FromImage(NewImage))
                {
                    newgraphics.DrawImage(FullsizeImage, 0, 0,
                                          new Rectangle(0, 0, FullsizeImage.Width, ThumbHeight), 
                                          GraphicsUnit.Pixel);
                    newgraphics.Flush();
                }
 
                NewImage.Save(outFilePath, ImageFormat.Png);
            }
        }

Comments

Popular posts from this blog

Enable Visual Studio to use more than 2GB of memory

Firefox and Chrome dark mode

Dealing with the morons who built Dell 7710 and RAID