本文介绍了如何压缩JPG图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有3300K的大小的JPG图像格式。

I have jpg image format with size of 3300K.

我尽量压缩图像=>让我改变了图像大小,但我仍然有非常大的尺寸

I try to compress the image => so i changed the image size but still i have very big size of the file ( ~ 800K )

The change size method code:

改变大小的方法的代码>内部静态影像resizeImage(图片imgToResize)
{
位图b =新位图(300,300);使用

(图形G = Graphics.FromImage((图)B))
{
//g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.InterpolationMode = InterpolationMode.Low;

g.DrawImage(imgToResize,0,0,300,300);

imgToResize.Dispose();
}

返回(图)B:
}

internal static Image resizeImage( Image imgToResize ) { Bitmap b = new Bitmap( 300, 300 ); using( Graphics g = Graphics.FromImage( ( Image )b ) ) { //g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.InterpolationMode = InterpolationMode.Low; g.DrawImage( imgToResize, 0, 0, 300, 300 ); imgToResize.Dispose(); } return ( Image )b; }



我必须压缩图像 - 即使图像的质量将不太然后原稿。

I must compress the image - even if the quality of the image will be less then the original.

我该怎么办呢?

推荐答案

使用呼叫调整大小功能如下代码

mg = image

newsize = height and width

Call Resize function using following code

Bitmap mg = new Bitmap(strUploadPath);
Size newSize = new Size(Convert.ToInt32(DispMaxWidth), Convert.ToInt32(DispMaxHeight));
Bitmap bp = ResizeImage(mg, newSize);
if (bp != null)
bp.Save(strUploadPath, System.Drawing.Imaging.ImageFormat.Jpeg);

private Bitmap ResizeImage(Bitmap mg, Size newSize)
        {
            double ratio = 0d;
            double myThumbWidth = 0d;
            double myThumbHeight = 0d;
            int x = 0;
            int y = 0;

            Bitmap bp;

            if ((mg.Width / Convert.ToDouble(newSize.Width)) > (mg.Height /
            Convert.ToDouble(newSize.Height)))
                ratio = Convert.ToDouble(mg.Width) / Convert.ToDouble(newSize.Width);
            else
                ratio = Convert.ToDouble(mg.Height) / Convert.ToDouble(newSize.Height);
            myThumbHeight = Math.Ceiling(mg.Height / ratio);
            myThumbWidth = Math.Ceiling(mg.Width / ratio);

            //Size thumbSize = new Size((int)myThumbWidth, (int)myThumbHeight);
            Size thumbSize = new Size((int)newSize.Width, (int)newSize.Height);
            bp = new Bitmap(newSize.Width, newSize.Height);
            x = (newSize.Width - thumbSize.Width) / 2;
            y = (newSize.Height - thumbSize.Height);
            // Had to add System.Drawing class in front of Graphics ---
            System.Drawing.Graphics g = Graphics.FromImage(bp);
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.PixelOffsetMode = PixelOffsetMode.HighQuality;
            Rectangle rect = new Rectangle(x, y, thumbSize.Width, thumbSize.Height);
            g.DrawImage(mg, rect, 0, 0, mg.Width, mg.Height, GraphicsUnit.Pixel);

            return bp;

        }

这篇关于如何压缩JPG图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 14:52