我想以这样的方式扩展UIImage,用户可以非常清晰地看到UIImage中的像素。当我把它放到UIImageView并向上缩放变换矩阵时,UIImage会出现抗锯齿和平滑。
有没有办法在更大的位图上下文中通过简单地重复每一行和每一列来获得更大的像素?我怎么能这样做?
#import <QuartzCore/CALayer.h>
view.layer.magnificationFilter = kCAFilterNearest
直接绘制到位图上下文时,我们可以使用:
CGContextSetInterpolationQuality(myBitmapContext, kCGInterpolationNone);
我也在尝试这个(在一个子层),我无法让它工作,它仍然模糊。这就是我必须做的事情:
const CGFloat PIXEL_SCALE = 2;
layer.magnificationFilter = kCAFilterNearest; //Nearest neighbor texture filtering
layer.transform = CATransform3DMakeScale(PIXEL_SCALE, PIXEL_SCALE, 1); //Scale layer up
//Rasterize w/ sufficient resolution to show sharp pixels
layer.shouldRasterize = YES;
layer.rasterizationScale = PIXEL_SCALE;
斯威夫特5
let image = UIImage(named: "Foo")
let scaledImageSize = image.size.applying(CGAffineTransform(scaleX: 2, y: 2))
UIGraphicsBeginImageContext(scaledImageSize)
let scaledContext = UIGraphicsGetCurrentContext()!
scaledContext.interpolationQuality = .none
image.draw(in: CGRect(origin: .zero, size: scaledImageSize))
let scaledImage = UIGraphicsGetImageFromCurrentImageContext()!
对于从CIImage创建的UIImage,您可以使用:
imageView.image = UIImage(CIImage: ciImage.imageByApplyingTransform(CGAffineTransformMakeScale(kScale, kScale)))