1

私は現在 TTPhotoViewController でいくつかの問題を抱えています: 私はいくつかの写真 (私の iPhone 3GS カメラから撮ったもの) を表示しようとしていますが、表示された写真の向きはほとんどの場合間違っています ...

たとえば、横向きモードで撮影した写真が正しく表示されることもあれば、逆さまになることもあれば、回転することもあります...

また、ポートレート モードで撮影した写真は回転する (したがって、画面全体よりも大きくなる) ことにも気付きましたが、iPhone を回転させると、画面にうまく収まります ...

私は怒っていると思います:)事前に感謝します。

編集:サイズの問題のようです。写真を縮小しようとしましたが、TTPhotoViewController はもう失敗しません。その後、元のサイズに再拡大しようとすると、問題が再び発生します。私の写真はiPhoneで撮ったので、その問題を「メモリ制限」の問題として理解できません。さらに、UIImageViewはそれをうまく表示します...

誰か提案があれば...

4

2 に答える 2

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;  
}
于 2012-04-16T10:04:08.233 に答える
1

おそらく、photoSourceのsize:属性を間違った値に設定しました。

編集:残念ながら、私はあなたの問題について別の提案はありませんが、警告があります。表示する前に画像を確実に拡大縮小する必要があります。1536x2048はiPhoneで処理するには大きすぎ、320x480画面ではまったく不要です。そうしないと、将来的にメモリ不足が原因でアプリがクラッシュする可能性があります。

于 2010-02-04T20:51:47.330 に答える