2010-02-04 31 views
1

我目前遇到一些麻煩與TTPhotoViewController:我試圖顯示一些照片(從我的iPhone 3GS的相機拍攝的),並顯示照片的方向幾乎都是錯誤的......Three20的TTPhotoViewController中的照片方向問題?

我的意思是比如在風景模式拍攝的照片有時會正確顯示,有時它會顛倒,有時它會旋轉...

我也注意到,在肖像模式拍攝的照片將被旋轉(採取超過整個屏幕),但旋轉iPhone將使其適合屏幕以及...

我想我要瘋了:)任何他lp將不勝感激,多謝先進。編輯: 看起來這是一個大小問題。 我試圖縮小我的圖片和TTPhotoViewController不會搞砸了,然後我嘗試將其重新縮放到其初始大小,並再次出現問題。 我無法將這個問題理解爲「內存限制」,因爲我的照片是用我的iPhone拍攝的;另外一個UIImageView顯示得很好......

如果任何人有什麼建議?

回答

1

你可能設置大小:在光源的屬性一些錯誤的值。

編輯:不幸的是我沒有你的問題的其他建議,但我有一個警告。在顯示之前,您肯定應該縮放圖像,1536x2048對於iPhone來說太大了,對於320x480的屏幕來說完全沒有必要。否則,由於未來內存不足,您肯定會發生應用程序崩潰 - 如果不是現在。

+0

不幸的是我設置的大小屬性來正確的價值,我甚至手動輸入它... 問題不在於大小,而是圖片以橫向(旋轉-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

+0

Arg看起來你是對的... 我試圖縮小我的圖片和TTPhotoViewController不會搞砸了,然後我嘗試將其重新縮放到其初始大小,並再次出現問題。 我無法將這個問題理解爲「內存限制」,因爲我的照片是用我的iPhone拍攝的;此外UIImageView顯示它很好... 如果您有任何建議,我會很高興。 – Taku 2010-02-04 21:58:41

2

從相機膠捲和畫廊調整的正確方向風景和肖像圖片我用這個函數:

-(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; 
}