gpt4 book ai didi

iphone - 抗锯齿 UIimage 看起来模糊或锯齿状

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:18:39 25 4
gpt4 key购买 nike

我想在一个代表 watch 编号的圆圈中绘制 12 个图像,我已经阅读了 stackoverflow 上关于具有透明边框的图像的所有主题,但它在我的情况下不起作用

-(UIImage *)addImageNumber_:(UIImage *)img {

int w = img.size.width;
int h = img.size.height;

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);
CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);
CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 1);
CGContextSetShouldAntialias(context,YES);
CGContextSetAllowsAntialiasing( context ,YES );
CGAffineTransform transform;

for (int x=0; x<=11; x++) {

UIImage *timg1 = [UIImage imageNamed:@"2.png"];

CGRect imageRect = CGRectMake(0, 0, timg1.size.width+2, timg1.size.height+2);
UIGraphicsBeginImageContext(imageRect.size);
[timg1 drawInRect:CGRectMake(1,1,timg1.size.width,timg1.size.height)];
timg1 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

transform = CGAffineTransformIdentity;

CGContextDrawImage(context, CGRectMake((w-26)/2, 0, 26, 30), timg1.CGImage);

transform = CGAffineTransformConcat(transform, CGAffineTransformMakeTranslation(-w/2, -w/2));
transform = CGAffineTransformConcat(transform, CGAffineTransformMakeRotation(radians(30)));
transform = CGAffineTransformConcat(transform, CGAffineTransformMakeTranslation(w/2, w/2));

CGContextConcatCTM(context, transform);
}

CGImageRef imageMasked = CGBitmapContextCreateImage(context);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
return [UIImage imageWithCGImage:imageMasked];
}
UIViewEdgeAntialiasing = YES;
UIImage *img = [UIImage imageNamed:@"test.png"];
UIImage *img2 = [self addImageNumber_:img ];
R1.image = img2;
[self.view addSubview:R1];

test img为 watch 背景,2.png为透明png,边框透明

enter image description here

12 点钟和 6 点钟的数字看起来不错,因为它们没有旋转,其余部分是锯齿状的

draw with text

最佳答案

永远不要说 UIGraphicsBeginImageContext(imageRect.size)。说 UIGraphicsBeginImageContextWithOptions(imageRect.size, NO, 0)。这样,在双分辨率屏幕上,您将获得双分辨率图形上下文。

您甚至可以尝试将分辨率值设为 4 以进一步提高分辨率。

当然,您从预先绘制的“2”图像开始这一事实可能会限制您的分辨率;你不能用母 pig 的耳朵做一个丝绸钱包。从头开始将“2”绘制为字符串可能会好得多。

关于iphone - 抗锯齿 UIimage 看起来模糊或锯齿状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14404877/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com