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

问题描述 投票:8回答:5

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

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

iphone cocoa-touch uikit uiimage core-graphics
5个回答
22
投票

#import <QuartzCore/CALayer.h>

view.layer.magnificationFilter = kCAFilterNearest


2
投票

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

CGContextSetInterpolationQuality(myBitmapContext, kCGInterpolationNone);

我在CGContextDrawImage very slow on iPhone 4上找到了这个


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;

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

-1
投票

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

imageView.image = UIImage(CIImage: ciImage.imageByApplyingTransform(CGAffineTransformMakeScale(kScale, kScale)))
© www.soinside.com 2019 - 2024. All rights reserved.