C#对jpg文件压缩后编码!
如题!
通常的做法是,先压缩 保存 再编码,示例代码如下:
Image img = Image.FromFile("C:\\0.jpg");
Bitmap bmp = new Bitmap(width, height);//width,height表示压缩后宽、高
Graphics grap = Graphics.FromImage(bmp);
grap.DrawImage(img, new Rectangle(0, 0, witdh, height));
bmp.Save("C:\\1.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
Image image = Image.FromFile("C:\\1.jpg");
MemoryStream ms = new MemoryStream();
image.Save(ms,ImageFormat.Jpeg);
ms.Flush();
ms.Seek(0,SeekOrigin.Begin);
byte [] buffer = new byte[ms.Length];
ms.Read(buffer,0,(int)ms.Length);/
问题:能否中间不保存,直接进行压缩编码呀!!!
------解决方案--------------------
Image img = Image.FromFile("C:\\0.jpg");
Bitmap bmp = new Bitmap(width, height);//width,height表示压缩后宽、高
Graphics grap = Graphics.FromImage(bmp);
grap.DrawImage(img, new Rectangle(0, 0, witdh, height));
MemoryStream ms = new MemoryStream();
bmp.Save(ms,ImageFormat.Jpeg);
byte [] buffer =ms.ToArray();