【解決方法】ビットマップをトリミングして元の鮮明な画像で保存する方法は?


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

私が試したこと:

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;
        }

解決策 1

JPEG は非可逆圧縮形式です。 画像を保存するたびに、結果の画像を小さくするために細部の一部が破棄されます。

品質をいじってみることができます:
方法: JPEG 圧縮レベルを設定する – Windows フォーム .NET Framework | マイクロソフト ラーン[^]

ただし、品質の低下を避けたい場合は、代わりに PNG などの可逆形式を使用する必要があります。

コメント

タイトルとURLをコピーしました