开发者

Loaded thumbnails not rotated even if large image is

开发者 https://www.devze.com 2023-02-25 02:05 出处:网络
I\'m writing a program where I have to load the thumbnails images first before proccessing them. img = Image.FromFile(file_path);

I'm writing a program where I have to load the thumbnails images first before proccessing them.

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, i开发者_Python百科mg_h1, null, IntPtr.Zero);

This code loads an image and then create a thumbnail.

Some of the photos taken by camera was rotated so i rotated them by 90degrees in IrfanView. Even so thumbnails loaded in my c# app are still rotated wrong (large image is ok).

How to work around this problem?


I don't see anything in your code that might rotate the image, so I'm thinking that there is something wrong with the image file that you're loading.

Specifically, my guess is that your image file has an embedded thumbnail which has NOT been rotated like the "main" image. You said you used IrfanView to rotate the images: take a look at this thread, and refresh the thumbnails. That might well solve your problem, and here's why:

Quoting MSDN's documentation for Image.GetThumbnailImage:

If the Image contains an embedded thumbnail image, this method retrieves the embedded thumbnail and scales it to the requested size. If the Image does not contain an embedded thumbnail image, this method creates a thumbnail image by scaling the main image.

0

精彩评论

暂无评论...
验证码 换一张
取 消