我已经读了几篇文章几乎所有人都建议使用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] 举报,一经查实,本站将立刻删除。