0

I'm trying to use CATransform3DRotate method to rotate an UIImage around its X axis, and get the rotated UIImage, but after rotation, some part will be cropped, and some part will be left black(transparent).

I'm using Brad Larson's GPUImage framework to do this.

My code is

filter = [[GPUImageTransformFilter alloc] init];
CATransform3D perspectiveTransform = CATransform3DIdentity;
perspectiveTransform.m34 = 0.4;
perspectiveTransform.m33 = 0.4;
perspectiveTransform = CATransform3DRotate(perspectiveTransform, 0.75, 1.0, 0.0, 0.0);


[(GPUImageTransformFilter *)filter setTransform3D:perspectiveTransform];
GPUImagePicture *sourcePicture = [[GPUImagePicture alloc] initWithImage:_myImage smoothlyScaleOutput:YES];
[sourcePicture addTarget:filter];
[filter useNextFrameForImageCapture];
[sourcePicture processImage];

_myImage = [filter imageFromCurrentFramebuffer];

Is there a way I can let the new UIImage suit the new size with out scaling down? Because scaling down may reduce the quality of the picture.

BTW, I tried to do it on a CALayer, but although the CALayer looks rotated, the actual UIImage is still the same.

Thanks heaps in advance!

park
  • 3
  • 3

1 Answers1

1

If you use UIImageView to display your image, then you can use the UIView's transform property to achieve what you need; please take a look at this answer for example. Alternatively, if you need UIImage rotated itself (not an image view), then please take a look at this answer.

Community
  • 1
  • 1
Nikolay Mamaev
  • 1,474
  • 1
  • 12
  • 21
  • Sorry Nikolay, I forgot to mention that, the rotation is around the X axis, and the result of the image is a trapezoid. That example is to rotate the image on a 2D level, and doesn't support 3D transformation.But thanks for the answer anyway – park Jun 14 '14 at 05:43
  • Thanks Nikolay, I've fixed it. Actually, it's doesn't matter if my rotation is a 3d or 2d one. When I use UIGraphicsBeginImageContext(CGSizeMake(_originalImage.size.width*2, _originalImage.size.height*2)); to double the size of the context, the image won't be cropped anymore. – park Jun 14 '14 at 06:25