如何在不平滑任何东西的情况下扩展UIImage?

时间:2010-10-10 13:25:39

标签: iphone cocoa-touch uikit uiimage core-graphics

我想以这样的方式扩展UIImage,用户可以非常清晰地看到UIImage中的像素。当我把它放到UIImageView并向上缩放变换矩阵时,UIImage会出现抗锯齿和平滑。

有没有办法在更大的位图上下文中通过简单地重复每一行和每一列来获得更大的像素?我怎么能这样做?

5 个答案:

答案 0 :(得分:22)

#import <QuartzCore/CALayer.h>

view.layer.magnificationFilter = kCAFilterNearest

答案 1 :(得分:2)

直接绘制到位图上下文时,我们可以使用:

CGContextSetInterpolationQuality(myBitmapContext, kCGInterpolationNone);

我在CGContextDrawImage very slow on iPhone 4

上找到了这个

答案 2 :(得分:1)

我也在尝试这个(在一个子图层上),我无法让它工作,它仍然模糊。这就是我必须要做的事情:

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;

答案 3 :(得分:1)

快速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()!

答案 4 :(得分:-1)

对于从CIImage创建的UIImage,您可以使用:

imageView.image = UIImage(CIImage: ciImage.imageByApplyingTransform(CGAffineTransformMakeScale(kScale, kScale)))