0
votes

I have a problem When I get an image from iPhone camera. i can get that in all orientations Like LeftLandscape, RightLandscape, Portrait and portrait upside down.

Now how can I rotate the image fetched from Camera Delegates to only one orientation i.e. Only in Portrait OR Landscape Right

Can anybody HElp ?

3

3 Answers

1
votes

Try this...

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;

Also refer this link...it will help you out...

http://www.platinumball.net/blog/2009/03/30/iphone-uiimage-rotation-and-mirroring/

0
votes

NYXImagesKit: Handy UIImage Categories

By Benjamin Godard

This is a handy set of categories on UIImage for rotating, resizing, filtering, enhancing and more, in an efficient and easy-to-use manner. Might be useful in some of your apps!

0
votes

Try this.It will be helpful

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