-6

画像をトリミングするためのC#コードがあります。

画像をトリミングすると(サイズ:191 KB、c#コードを使用)、結果の(トリミングされた)画像のサイズが大きくなります(サイズ:2.44MB)

トリミング後にサイズが大きくなる理由を教えてください..???

 Bitmap source = new Bitmap(@"F:\images\Row" + i + "Col" + j + ".jpg");
                Rectangle section = new Rectangle(new Point(0, 0), new Size(1362, 761));
                Bitmap CroppedImage = CropImage(source, section);
                CroppedImage.Save(@"file path\Row" + i + "Col" + j + ".jpg");



    public Bitmap CropImage(Bitmap source, Rectangle section)
    {
        // An empty bitmap which will hold the cropped image
        Bitmap bmp = new Bitmap(section.Width, section.Height);

        Graphics g = Graphics.FromImage(bmp);

        // Draw the given area (section) of the source image
        // at location 0,0 on the empty bitmap (bmp)
        g.DrawImage(source, 0, 0, section, GraphicsUnit.Pixel);

        return bmp;
    }
4

1 に答える 1

6

テレパシーパワー:ディスク上のファイルのサイズについて話し、元の圧縮ファイル(JPGなど)と非圧縮形式(BMPなど)で保存されたトリミングされたバージョンを比較します。

修正:トリミングされた画像を圧縮形式で保存します。

2つの引数を指定してImage.Saveを使用すると、形式を指定できます(つまり、サンプルで使用する1つの引数バージョンとは異なります)。

記事の例:

// Construct a bitmap from the button image resource.
Bitmap bmp1 = new Bitmap(typeof(Button), "Button.bmp");

// Save the image as a GIF.
bmp1.Save("c:\\button.gif", System.Drawing.Imaging.ImageFormat.Gif);
于 2013-03-27T07:06:08.267 に答える