I have a image with pixel size: 3024 * 3024
I have a custom UIView with logical size: 207 * 207, and layer.contentsScale is 3, so pixel size is 621 * 621.
I want to draw this UIImage in my custom UIView, the code in draw(rect:) like this;
and the result is very bad, picture is aliasing, I tried much solution, but not work well.
I have a custom UIView with logical size: 207 * 207, and layer.contentsScale is 3, so pixel size is 621 * 621.
I want to draw this UIImage in my custom UIView, the code in draw(rect:) like this;
Code Block var image: UIImage? { didSet { setNeedDisplay() } } override func draw(_ rect: CGRect) { guard let ctx = UIGraphicsGetCurrentContext() else { return } ctx.addRect(bounds) ctx.setFillColor(UIColor.black.cgColor) ctx.fillPath() if var im = image { let size = Math.getMaxSizeWithAspect(size: CGSize(width: bounds.width, height: bounds.height), radioWidthToHeight: im.size.width / im.size.height) im.draw(in: CGRect(x: (bounds.width - size.width) / 2, y: (bounds.height - size.height) / 2, width: size.width, height: size.height)) }
and the result is very bad, picture is aliasing, I tried much solution, but not work well.
Code Block // not work list... ctx.setShouldAntialias(true) ctx.setAllowsAntialiasing(true) ctx.interpolationQuality = .high layer.allowsEdgeAntialiasing = true layer.minificationFilter = .trilinear