即使大图像,加载的缩略图也不会旋转

时间:2011-04-13 12:35:12

标签: c# image-manipulation thumbnails

我正在编写一个程序,我必须首先加载缩略图图像才能处理它们。

img = Image.FromFile(file_path);

int img_w = img.Width;
int img_h = img.Height;

int desired_size = 150;

int img_h1 = desired_size;
double resize = (double)img_h / (double)img_w;
resize = (double)desired_size * resize;
img_h1 = (int)resize;

thumb = img.GetThumbnailImage(desired_size, img_h1, null, IntPtr.Zero);

此代码加载图像,然后创建缩略图。

相机拍摄的部分照片已旋转,因此我在IrfanView中将它们旋转了90度。即便如此,我的c#app中加载的缩略图仍然旋转错误(大图像没问题)。

如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我在代码中看不到任何可能会旋转图片的内容,因此我认为您正在加载的图片文件存在问题。

具体来说,我的猜测是你的图像文件有一个嵌入式缩略图,它没有按照" main"图片。你说你用IrfanView来旋转图像:take a look at this thread,然后刷新缩略图。这可能很好地解决了你的问题,原因如下:

引用MSDN's documentation for Image.GetThumbnailImage

  

如果图像包含嵌入式   缩略图图像,此方法检索   嵌入的缩略图并缩放它   达到要求的尺寸。如果是图像   不包含嵌入的缩略图   图像,此方法创建缩略图   缩放主图像的图像。