public void CreateThumbnail(Image img1, Photo photo, string targetDirectoryThumbs)
{
int newWidth = 700;
int newHeight = 700;
double ratio = 0;
if (img1.Width > img1.Height)
{
ratio = img1.Width/(double)img1.Height;
newHeight = (int)(newHeight/ratio);
}
else
{
ratio = img1.Height/(double)img1.Width;
newWidth = (int)(newWidth/ratio);
}
Image bmp1 = img1.GetThumbnailImage(newWidth, newHeight, null, IntPtr.Zero);
bmp1.Save(targetDirectoryThumbs + photo.PhotoID + ".jpg");
img1.Dispose();
bmp1.Dispose();
}
我已经放了700px
以便您可以更好地了解问题。 这里是original图片和resized之一。C#创建缩略图(低质量和大尺寸问题)
有什么好的建议吗?
感谢,
岛
虽然扩展名是“jpg”,你实际上是保存在PNG格式(默认)的BMP1图像。要让Jpeg使用bmp1.Save(“name”,ImageFormat.Jpeg)。 – munissor 2010-05-18 13:56:45