我已经阅读了几篇文章。几乎每个人都建议使用 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, 0, colorSpace, kCGImageAlphaPremultipliedLast);
CGContextClearRect(context, CGRectMake(0, 0, newSize.width, newSize.height));
CGContextDrawImage(context, CGRectMake(0, 0, newSize.width, 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();
尝试使用此代码移动,据我所知,我不久前使用过它,它制作了一个带有圆角的图像,您可以在目标中四处移动。但它似乎可以很好地扩展......
关于ios - 带有圆角的 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10563986/