Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Is your goal is to obtain just the exact copy of what you are editing, but with the size of the original image? I guess it could be obtained by something like this:</p> <pre><code>- (UIImage *)padImage:(UIImage *)img to:(CGSize)size { if (size.width &lt; img.size.width &amp;&amp; size.height &lt; img.size.height) return img; size.width = MAX(size.width, img.size.width); size.height = MAX(size.height, img.size.height); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef context = CGBitmapContextCreate(NULL, size.width, size.height, 8, 0, colorSpace, kCGImageAlphaPremultipliedLast); CGRect centeredRect = CGRectMake((size.width - img.size.width)/2.0, (size.height - img.size.height)/2.0, img.size.width, img.size.height); CGContextDrawImage(context, centeredRect, [img CGImage]); CGImageRef imageRef = CGBitmapContextCreateImage(context); CGColorSpaceRelease(colorSpace); CGContextRelease(context); UIImage *paddedImage = [UIImage imageWithCGImage:imageRef]; CGImageRelease(imageRef); return paddedImage; } // final image size must be 640x480 - (void)generateFinalImage { float rotatableCanvasWidth = 495.0; float rotatableCanvasHeight = 320.0; UIImage *tmp = self.importedRawImage; CGSize size = self.importedRawImage.size; NSLog(NSStringFromCGSize(size)); tmp = [self padImage:tmp to:CGSizeMake(rotatableCanvasWidth, rotatableCanvasHeight)]; CIImage *ciImage = [[CIImage alloc] initWithImage:[tmp imageWithTransform:self.importedImageView.transform]]; CGPoint center = CGPointMake(size.width / 2.0, size.height / 2.0); CIContext *context = [CIContext contextWithOptions:nil]; CGRect r = ciImage.extent; r.origin.x = (r.size.width - rotatableCanvasHeight) / 2.0; r.origin.y = (r.size.height - rotatableCanvasWidth) / 2.0; r.size.width = rotatableCanvasHeight; r.size.height = rotatableCanvasWidth; self.finalImage = [UIImage imageWithCGImage:[context createCGImage:ciImage fromRect:r] scale:1.0 orientation:UIImageOrientationUp]; self.finalImage = [self.finalImage resizedImage:CGSizeMake(100.0f, 134.0f) interpolationQuality:kCGInterpolationHigh]; self.previewImageView.image = self.finalImage; } </code></pre>
 

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