I want a 100% c# github project that can crop and save a image.save and crop both is must
I want a 100% c# github project that can crop and save a image
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
I want a 100% c# github project that can crop and save a image.save and crop both is must
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jayraj ChhayaRank #304 · 8.2K reputationPosted Mar 8, 2024, 2:37 AM EST
To achieve image cropping and saving functionality in C#
using System; using System.Drawing; class ImageProcessor { public void CropAndSaveImage(string sourceImagePath, string outputPath, int x, int y, int width, int height) { using (var originalImage = Image.FromFile(sourceImagePath)) { using (var croppedImage = new Bitmap(width, height)) { using (var graphics = Graphics.FromImage(croppedImage)) { graphics.DrawImage(originalImage, new Rectangle(0, 0, width, height), new Rectangle(x, y, width, height), GraphicsUnit.Pixel); croppedImage.Save(outputPath); } } } } } class Program { static void Main() { ImageProcessor processor = new ImageProcessor(); processor.CropAndSaveImage("input.jpg", "output.jpg", 50, 50, 200, 200); } }You can enhance this code further by adding error handling, input validation, and additional image processing features based on your requirements.