gpt4 book ai didi

ios - CGContext 缩放到视网膜

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

我有这段代码可以呈现一个内部带有动态文本的自定义滑动条 handle 。问题是我无法将其缩放到视网膜分辨率。它可以在所有设备上正确绘制并且大小合适,但在视网膜上分辨率较低。如何更改此代码以使最终图像分辨率加倍?

-(UIImage *)addText:(UIImage *)img{
int w = img.size.width;
int h = img.size.height;



CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 0, colorSpace,kCGImageAlphaPremultipliedFirst);
CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);

char* text= (char *)[[NSString stringWithFormat:@"$%d", (int)betSlider.value * 5] cStringUsingEncoding:NSASCIIStringEncoding];
CGContextSetShouldAntialias(context, true);
CGContextSelectFont(context, "TimesNewRomanPS-BoldMT",mainFrame.size.width/22, kCGEncodingMacRoman);
CGContextSetTextDrawingMode(context, kCGTextFill);
CGContextSetRGBFillColor(context,255,255,255, 1);
CGContextShowTextAtPoint(context,(img.size.width-(strlen(text)*strlen(text)*(img.size.width/27)))/2.5,img.size.width/2.5,text, strlen(text));
CGImageRef imgCombined = CGBitmapContextCreateImage(context);


CGContextRelease(context);
CGColorSpaceRelease(colorSpace);

UIImage *retImage = [UIImage imageWithCGImage:imgCombined];
CGImageRelease(imgCombined);

return retImage;
}

最佳答案

像这样更改创建上下文:

CGFloat scale = [[UIScreen mainScreen] scale]
CGContextRef context = CGBitmapContextCreate(NULL, w * scale, h * scale, 8, 0, colorSpace,kCGImageAlphaPremultipliedFirst);

关于ios - CGContext 缩放到视网膜,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22579474/

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