10度旋转图像被截断
我旋转图像时:
UIImage *image = [UIImage imageNamed:@"doneBtn.png"];
CGImageRef imgRef = image.CGImage;
CGFloat width = CGImageGetWidth(imgRef);
CGFloat height = CGImageGetHeight(imgRef);
CGAffineTransform transform = CGAffineTransformIdentity;
CGRect bounds = CGRectMake(0, 0, width, height);
transform = CGAffineTransformRotate(transform, degreesToRadians(10));
UIGraphicsBeginImageContext(bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextConcatCTM(context, transform);
CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0,0,width,height), imgRef);
UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
img.image=imageCopy;
当我显示图像时,我看到它在 10 度以下,但图像的边缘被切断。
有人知道如何解决这个问题吗? 这是用于澄清的图像。
替代文本 http://img197.imageshack.us/img197/7077/problemkfr.png< /a>
我昨天一整天都在尝试,但无法弄清楚。
另一个示例图像:
替代文本 http://img25.imageshack.us/img25/3370/ afbeelding6b.png
I rotate my image with:
UIImage *image = [UIImage imageNamed:@"doneBtn.png"];
CGImageRef imgRef = image.CGImage;
CGFloat width = CGImageGetWidth(imgRef);
CGFloat height = CGImageGetHeight(imgRef);
CGAffineTransform transform = CGAffineTransformIdentity;
CGRect bounds = CGRectMake(0, 0, width, height);
transform = CGAffineTransformRotate(transform, degreesToRadians(10));
UIGraphicsBeginImageContext(bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextConcatCTM(context, transform);
CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0,0,width,height), imgRef);
UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
img.image=imageCopy;
When I display the image, I see it under my 10 degree but the image is cut off on the edges.
Does somebody know how to fix this? Here's an image for clarification.
alt text http://img197.imageshack.us/img197/7077/problemkfr.png
I have been trying all day yesterday, but can't figure it out.
Another example image:
alt text http://img25.imageshack.us/img25/3370/afbeelding6b.png
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
代码 IN SliderAppViewController.h
代码 IN SliderApp.m
然后在 IB 中建立连接
CODE IN SliderAppViewController.h
CODE IN SliderApp.m
then make connection in IB
你的问题是你的 CALayer 的锚点,我这里没有示例代码,但是如果你使用视图 CALayer 的锚点属性,你应该能够让视图看起来像你想要的那样。 我稍后会尝试发布一些示例代码
Your problem here is the anchor of your CALayer, I dont have example code right here with me, but if you play with the anchor property of the view CALayer you should be able to get the view to look like you want. I will try and post some sample code later
我现在解决了它,我必须更改边界的宽度/高度值和
CGContextDrawImage 中的 x/y
I solved it now, i have to change the width/height value of bounds and
the x/y in CGContextDrawImage