裁剪后图像尺寸增加

时间:2013-03-27 06:55:32

标签: c#

我有c#代码裁剪图片。

当我裁剪图像(尺寸:191 KB,使用我的c#代码)时,结果(裁剪)图像的尺寸增加(尺寸:2.44 MB)

请告诉我为什么裁剪后尺寸增加.. ???

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

1 个答案:

答案 0 :(得分:6)

Telepathic power:您正在谈论磁盘上文件的大小,并将原始压缩文件(可能是JPG)与以非压缩格式(可能是BMP)保存的裁剪版本进行比较。

修复:以压缩格式保存裁剪后的图像。

带有2个参数的

Image.Save允许您指定格式(即与您在样本中使用的一个参数版本不同)。

文章中的例子:

// 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);