我想提請在代表手錶的數字圓圈12張圖像,我已經閱讀計算器關於與透明邊框圖像的所有議題,但它不是我的情況下工作抗鋸齒的UIImage看起來模糊或鋸齒狀
-(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];
測試IMG是手錶的背景,2.png是一個透明的PNG有透明邊界
號的牛逼12'o時鐘和6'o時鐘看起來不錯,因爲他們不旋轉,其餘都是鋸齒
抗鋸齒不應與UIImageViews的一個問題。我認爲這可能是另一個問題。你是否急劇縮小了你使用的圖像? –
沒有圖像被縮小,它們都具有原始尺寸 –
您獲得的質量是技術上可行的。當您創建原始圖像時,會使用最佳的抗鋸齒功能。當你旋轉它時,它不再是最佳的。每次轉換隻會導致質量下降。最好使用文本繪圖功能來創建時鐘。 – Codo