Iphone 三部曲中的照片定向问题20';TTPhotoViewController?
我目前在TTPhotoViewController上遇到了一些问题:我试图显示一些照片(从我的iPhone 3GS相机拍摄),而显示的照片的方向几乎总是错误的 我的意思是,例如,在横向模式下拍摄的照片有时会正确显示,有时会颠倒,有时会旋转 我还注意到,在肖像模式下拍摄的照片会被旋转(因此会比整个屏幕拍摄更多),但旋转iPhone会使其与屏幕很好地匹配 我想我快疯了:)任何帮助都将不胜感激,提前谢谢 编辑: 这似乎是个大小问题。 我试图缩小我的图片,TTPhotoViewController不再出错,然后我尝试将其重新缩放到初始大小,问题再次出现。 我不能把这个问题理解为“内存限制”,因为我的照片是用iPhone拍的;此外,UIImageView可以很好地显示它Iphone 三部曲中的照片定向问题20';TTPhotoViewController?,iphone,orientation,three20,photo,Iphone,Orientation,Three20,Photo,我目前在TTPhotoViewController上遇到了一些问题:我试图显示一些照片(从我的iPhone 3GS相机拍摄),而显示的照片的方向几乎总是错误的 我的意思是,例如,在横向模式下拍摄的照片有时会正确显示,有时会颠倒,有时会旋转 我还注意到,在肖像模式下拍摄的照片会被旋转(因此会比整个屏幕拍摄更多),但旋转iPhone会使其与屏幕很好地匹配 我想我快疯了:)任何帮助都将不胜感激,提前谢谢 编辑: 这似乎是个大小问题。 我试图缩小我的图片,TTPhotoViewController不再出
如果有人有建议…您可能将photoSource的size:attribute设置为错误的值
编辑:不幸的是,我没有其他关于你的问题的建议,但是我有一个警告。在显示图像之前,您一定要缩放图像,1536x2048对于iphone来说太大了,无法处理,对于320x480屏幕来说完全没有必要。否则,您肯定会在将来由于内存不足而导致应用程序崩溃—如果不是现在。要从相机卷和多媒体资料中以正确方向调整横向和纵向图像的大小,我使用此功能:
-(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;
}
不幸的是,我将size属性设置为正确的值,我甚至手动输入了它。。。问题不在于大小,而在于图片是以横向(旋转-PI/2)显示的,实际上是纵向的,这将是正确的照片方向。我尝试将照片加载到UIImage中,使用UIImage,方向正常,我无法理解。。。你还有别的想法吗?加载下面照片的代码:MockPhoto*m=[[MockPhoto alloc]initWithURL:@”bundle://img3.jpg“smallURL:@”bundle://img3.jpg“大小:CGSizeMake(1536.02048.0)];阿格看来你是对的。。。我试图缩小我的图片,TTPhotoViewController不再出错,然后我尝试将其重新缩放到初始大小,问题再次出现。我不能把这个问题理解为“内存限制”,因为我的照片是用iPhone拍的;此外,UIImageView可以很好地显示它。。。如果你有什么建议,我会很高兴的。