從相機膠捲和畫廊調整的正確方向風景和肖像圖片我用這個函數:
-(UIImage *)resizeImage:(UIImage *)image
{
CGImageRef imageRef = [image CGImage];
CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(imageRef);
CGColorSpaceRef colorSpaceInfo = CGColorSpaceCreateDeviceRGB();
if (alphaInfo == kCGImageAlphaNone)
{
alphaInfo = kCGImageAlphaNoneSkipLast;
}
int width, height;
width = 640;
height = 480;
CGContextRef bitmap;
if (image.imageOrientation == UIImageOrientationUp | image.imageOrientation == UIImageOrientationDown)
{
bitmap = CGBitmapContextCreate(NULL, width, height, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), colorSpaceInfo, alphaInfo);
}
else
{
bitmap = CGBitmapContextCreate(NULL, height, width, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), colorSpaceInfo, alphaInfo);
}
if (image.imageOrientation == UIImageOrientationLeft)
{
NSLog(@"image orientation left");
CGContextRotateCTM (bitmap, radians(90));
CGContextTranslateCTM (bitmap, 0, -height);
}
else if (image.imageOrientation == UIImageOrientationRight)
{
NSLog(@"image orientation right");
CGContextRotateCTM (bitmap, radians(-90));
CGContextTranslateCTM (bitmap, -width, 0);
}
else if (image.imageOrientation == UIImageOrientationUp)
{
NSLog(@"image orientation up");
}
else if (image.imageOrientation == UIImageOrientationDown)
{
NSLog(@"image orientation down");
CGContextTranslateCTM (bitmap, width,height);
CGContextRotateCTM (bitmap, radians(-180.));
}
CGContextDrawImage(bitmap, CGRectMake(0, 0, width, height), imageRef);
CGImageRef ref = CGBitmapContextCreateImage(bitmap);
UIImage *result = [UIImage imageWithCGImage:ref];
CGContextRelease(bitmap);
CGImageRelease(ref);
return result;
}
不幸的是我設置的大小屬性來正確的價值,我甚至手動輸入它... 問題不在於大小,而是圖片以橫向(旋轉-PI/2)顯示,確實是縱向顯示,這將是正確的照片方向。 我試圖加載照片到UIImage和UIImage,方向是好的,我不明白... 你有任何其他的想法嗎? 我的代碼加載下面的照片: MockPhoto * M = [[MockPhoto的alloc] initWithURL:@ 「束://img3.jpg」 smallURL:@ 「束://img3.jpg」 尺寸: CGSizeMake(1536.0,2048.0)]; – Taku 2010-02-04 21:05:33
Arg看起來你是對的... 我試圖縮小我的圖片和TTPhotoViewController不會搞砸了,然後我嘗試將其重新縮放到其初始大小,並再次出現問題。 我無法將這個問題理解爲「內存限制」,因爲我的照片是用我的iPhone拍攝的;此外UIImageView顯示它很好... 如果您有任何建議,我會很高興。 – Taku 2010-02-04 21:58:41