日期:2014-05-20  浏览次数:20781 次

有关操作JPG图片的问题,谢谢指点
C#中如何实现将一1600*1200尺寸的JPG文件转化为一640*480的尺寸

------解决方案--------------------
???
我反问一下楼主,在C#怎么操作的JPG文件,是当做Bitmap处理的吗?
我不会这个...
------解决方案--------------------
string oldImagePath = @ "c:\x.jpg ";
System.Drawing.Image oldImage = System.Drawing.Image.FromFile(oldImagePath);
int newWidth = 640;
int newHeight = 480;

System.Drawing.Image thumbnailImage = oldImage.GetThumbnailImage(newWidth, newHeight, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
System.Drawing.Bitmap bm = new System.Drawing.Bitmap(thumbnailImage);

//处理JPG质量的函数
System.Drawing.Imaging.ImageCodecInfo ici = GetEncoderInfo( "image/jpeg ");
if (ici != null)
{
System.Drawing.Imaging.EncoderParameters ep = new System.Drawing.Imaging.EncoderParameters(1);
ep.Param[0] = new System.Drawing.Imaging.EncoderParameter(Encoder.Quality, (long)100);
bm.Save(@ "c:\new.jpg ", ici, ep);

//释放所有资源,不释放,可能会出错误。
ep.Dispose();
ep = null;
}
ici = null;

bm.Dispose();
bm = null;

thumbnailImage.Dispose();
thumbnailImage = null;
oldImage.Dispose();
oldImage = null;

private static bool ThumbnailCallback( )
{
return false;
}

private static ImageCodecInfo GetEncoderInfo( String mimeType )
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for (j = 0 ; j < encoders.Length ; ++j)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
return null;
}
------解决方案--------------------
mark..
------解决方案--------------------
net_lover(【孟子E章】) ( ) 信誉:140 Blog
就是高!
收藏下!
------解决方案--------------------
高手就是高手 顶一下
------解决方案--------------------
又见钻石! 学习