【发布时间】:2012-03-12 11:34:36
【问题描述】:
我有问题 当我从 iPhone 相机获取图像时。我可以在所有方向上得到它,比如 LeftLandscape、RightLandscape、Portrait 和 Portrait 颠倒。
现在如何将从相机代表获取的图像旋转到仅一个方向,即仅在纵向或横向右侧
有人可以帮忙吗?
【问题讨论】:
标签: iphone uiimage orientation
我有问题 当我从 iPhone 相机获取图像时。我可以在所有方向上得到它,比如 LeftLandscape、RightLandscape、Portrait 和 Portrait 颠倒。
现在如何将从相机代表获取的图像旋转到仅一个方向,即仅在纵向或横向右侧
有人可以帮忙吗?
【问题讨论】:
标签: iphone uiimage orientation
试试这个……
CGSize size = sizeOfImage;
UIGraphicsBeginImageContext(size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextRotateCTM(ctx, angleInRadians);
CGContextDrawImage(UIGraphicsGetCurrentContext(),
CGRectMake(0,0,size.width, size.height),
image);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
另请参阅此链接...它将帮助您...
http://www.platinumball.net/blog/2009/03/30/iphone-uiimage-rotation-and-mirroring/
【讨论】:
NYXImagesKit: Handy UIImage Categories
本杰明·戈达尔
这是 UIImage 上的一组方便的类别,用于以高效且易于使用的方式进行旋转、调整大小、过滤、增强等。可能对您的某些应用有用!
【讨论】:
试试这个,会有帮助的
-(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;//[image size].width;
height = 640;//[image size].height;
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;
}
【讨论】: