微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ios – UIImage与圆角

我已经读了几篇文章几乎所有人都建议使用QuartzCore / QuartzCore.h与layer.cornerRadius

我已经尝试了这种方法和一些更多的方法

那么一旦图像不动,一切都可以正常运行。

但在我的项目中,我总是移动我的图像。
如果我添加角半径或阴影,图像运动不再平滑。而且看起来很可爱!

那就是我调整图像大小的方式:

CGSize newSize = CGSizeMake(200*height/image.size.height,280);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(nil,newSize.width,newSize.height,8,colorSpace,kCGImageAlphaPremultipliedLast);
CGContextClearRect(context,CGRectMake(0,newSize.height));
CGContextDrawImage(context,newSize.height),image.CGImage);
CGImageRef scaledImage = CGBitmapContextCreateImage(context);
CGColorSpaceRelease(colorSpace);
CGContextRelease(context);
UIImage *newImage = [UIImage imageWithCGImage: scaledImage];
CGImageRelease(scaledImage);

我想知道一个很好的方式来调整我的形象,添加阴影,角半径,还有我的图像的顺利移动。

解决方法

// Get your image somehow
UIImage *image = [UIImage imageNamed:@"image.jpg"];

// Begin a new image that will be the new image with the rounded corners 
// (here with the size of an UIImageView)
 UIGraphicsBeginImageContextWithOptions(imageView.bounds.size,NO,[UIScreen mainScreen].scale);

 // Add a clip before drawing anything,in the shape of an rounded rect
  [[UIBezierPath bezierPathWithRoundedRect:imageView.bounds 
                        cornerRadius:10.0] addClip];
 // Draw your image
[image drawInRect:imageView.bounds];

 // Get the image,here setting the UIImageView image
  imageView.image = UIGraphicsGetimageFromCurrentimageContext();

 // Lets forget about that we were drawing
  UIGraphicsEndImageContext();

尝试移动这个代码,据我记得,我一直使用这一点,使一个圆角的图像,你可以移动到目标。但它似乎规模很好…

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐