Click here to Skip to main content
15,888,271 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
When I crop a bitmap from an image, the clarity of the cropped bitmap is reduced. How to bring the original clarity of the bitmap when cropping

temp = temrary bitmap image
varas.ptval = orignal image


What I have tried:

Bitmap temp;
Bitmap croped;
Rectangle rectangle = new Rectangle();
rectangle.Height = varas.Rect_H;
rectangle.Width = varas.Rect_W;
rectangle.X = varas.Rect_X;
rectangle.Y = varas.Rect_Y;
temp = varas.ptval;
croped = cropBitmap(temp, rectangle);
varas.RGBcrop = croped;
croped.Save(paths + "\\" + "SPR_" + ".jpeg", ImageFormat.Jpeg);




static public Bitmap cropBitmap(Bitmap bitmap, Rectangle rectangle)
        {
            Bitmap cropped = bitmap.Clone(rectangle, bitmap.PixelFormat);
            return cropped;
        }
Posted
Updated 18-Dec-22 23:14pm

1 solution

JPEG is a lossy compression format. Every time you save the image, some of the detail will be thrown away to make the resulting image smaller.

You can try playing around with the quality:
How to: Set JPEG Compression Level - Windows Forms .NET Framework | Microsoft Learn[^]

But if you want to avoid losing quality, you need to use a lossless format like PNG instead.
 
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