Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to handle Image rotation issue in IOS image cropping
    primarykey
    data
    text
    <p>I am working on camera related app.Here I am taking image from camera and need to crop it and later fix that to image view.For cropping the image I am using OpenGL.My problem is I am after cropping the image is getting rotated 180 degrees.But this is not happening all the time.Some times I am getting the original image itself.</p> <pre><code>-(void)showResult { NSLog(@"showResult called" ); UIImage *imageCrop; float scaleCrop; if (_sourceImage.size.width &gt;= IMAGEWIDTH) { scaleCrop = IMAGEWIDTH / _sourceImage.size.width; imageCrop = [ImageCropViewController scaleImage:_sourceImage with:CGSizeMake(_sourceImage.size.width*scaleCrop, _sourceImage.size.height*scaleCrop)]; } else { scaleCrop = 1; imageCrop = _sourceImage; } float scale = _sourceImage.size.width / resizeImage.size.width * 2; IplImage *iplImage = [ImageCropViewController CreateIplImageFromUIImage:imageCrop] ; Quadrilateral rectan; rectan.point[0].x = _touchLayer.rectan.pointA.x*scale*scaleCrop; rectan.point[0].y = _touchLayer.rectan.pointA.y*scale*scaleCrop; rectan.point[1].x = _touchLayer.rectan.pointB.x*scale*scaleCrop; rectan.point[1].y = _touchLayer.rectan.pointB.y*scale*scaleCrop; rectan.point[2].x = _touchLayer.rectan.pointC.x*scale*scaleCrop; rectan.point[2].y = _touchLayer.rectan.pointC.y*scale*scaleCrop; rectan.point[3].x = _touchLayer.rectan.pointD.x*scale*scaleCrop; rectan.point[3].y = _touchLayer.rectan.pointD.y*scale*scaleCrop; IplImage* dest = cropDoc2(iplImage,rectan); IplImage *image = cvCreateImage(cvGetSize(dest), IPL_DEPTH_8U, dest-&gt;nChannels); cvCvtColor(dest, image, CV_BGR2RGB); cvReleaseImage(&amp;dest); tempImage = [ImageCropViewController UIImageFromIplImage:image withImageOrientation:_sourceImage.imageOrientation]; [self crop:tempImage]; cvReleaseImage(&amp;image); } </code></pre> <p>After that the below method is called</p> <pre><code>+ (UIImage *)UIImageFromIplImage:(IplImage *)image withImageOrientation:(UIImageOrientation)orientation { NSLog(@"UIImageFromIplImage called" ); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); NSData *data = [NSData dataWithBytes:image-&gt;imageData length:image-&gt;imageSize]; CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge CFDataRef)data); CGImageRef imageRef = CGImageCreate(image-&gt;width, image-&gt;height, image-&gt;depth, image-&gt;depth * image-&gt;nChannels, image-&gt;widthStep, colorSpace, kCGImageAlphaNone|kCGBitmapByteOrderDefault, provider, NULL, false, kCGRenderingIntentDefault); UIImage *ret = [UIImage imageWithCGImage:imageRef scale:1 orientation:orientation]; CGImageRelease(imageRef); CGDataProviderRelease(provider); CGColorSpaceRelease(colorSpace); return ret; } </code></pre> <p>Then I am rotating the Image as per my requirement</p> <pre><code>-(void)crop:(UIImage*)image { NSLog(@"crop called" ); //Adjust the image size, to scale the image to 1013 of width float targetWidth = 1009.0f; float scale = targetWidth / image.size.width; float scaleheight = image.size.height * scale; UIImage *imageToSent = [ImageCropViewController scaleImage:image with:CGSizeMake(targetWidth, scaleheight)]; if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft) { NSLog(@"###########Image orientation is UIInterfaceOrientationLandscapeLeft###########"); imageToSent = [[UIImage alloc] initWithCGImage:imageToSent.CGImage scale:1.0f orientation:UIImageOrientationDown]; } NSData *imageData = UIImageJPEGRepresentation(imageToSent,0.75); NSDate *now = [NSDate dateWithTimeIntervalSinceNow:0]; NSString *caldate = [now description]; appDelegate.imagefilePath= [NSString stringWithFormat:@"%@/%@.jpg", DOCUMENTS_FOLDER,caldate]; [imageData writeToFile:appDelegate.imagefilePath atomically:YES]; appDelegate.cropimage=imageToSent; } </code></pre> <p>I am not getting where it was gone wrong.It is killing my time.Please help me.</p> <p>Thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload