我正在使用以下代码对我加载的图像执行一些操作,但我发现当它在视网膜显示器上时显示变得模糊
- (UIImage*)createImageSection:(UIImage*)image section:(CGRect)section
{
float originalWidth = image.size.width ;
float originalHeight = image.size.height ;
int w = originalWidth * section.size.width;
int h = originalHeight * section.size.height;
CGContextRef ctx = CGBitmapContextCreate(nil, w, h, 8, w * 8,CGImageGetColorSpace([image CGImage]), kCGImageAlphaPremultipliedLast);
CGContextClearRect(ctx, CGRectMake(0, 0, originalWidth * section.size.width, originalHeight * section.size.height)); // w + h before
CGContextTranslateCTM(ctx, (float)-originalWidth * section.origin.x, (float)-originalHeight * section.origin.y);
CGContextDrawImage(ctx, CGRectMake(0, 0, originalWidth, originalHeight), [image CGImage]);
CGImageRef cgImage = CGBitmapContextCreateImage(ctx);
UIImage* resultImage = [[UIImage alloc] initWithCGImage:cgImage];
CGContextRelease(ctx);
CGImageRelease(cgImage);
return …Run Code Online (Sandbox Code Playgroud) 我有一个UIView,它从drawRect:rect中画一个圆圈.在Retina显示屏上阅读Apple dev信息后,似乎使用Core Graphics意味着图纸会自动利用更高的分辨率.然而,与徽章图标中的类似圆圈相比,这个简单的圆圈看起来相当粗糙.显然我正在将它与具有光泽和阴影的东西进行比较,但我认为很明显我的画面并没有被画出来.我尝试拍摄苹果图标徽章和我的圈子的屏幕截图,他们在我的Mac上看起来一样 - 不过在看电话的时候差别很明显.这里有什么简单的东西吗?
这是我在drawRect:rect中使用的绘图代码
UIBezierPath* aPath = [UIBezierPath bezierPathWithOvalInRect:
CGRectMake(0, 0, 22, 22)];
[[UIColor whiteColor] setStroke];
[[UIColor redColor] setFill];
CGContextRef aRef = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(aRef, 10, 10);
aPath.lineWidth = 3;
[aPath fill];
[aPath stroke];
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助,Rob
我正在尝试添加一个文本,UIImage我得到一个像素化的绘图.
我尝试了其他一些没有成功的答案:
我的代码:
-(UIImage *)addText:(UIImage *)imgV text:(NSString *)text1
{
int w = self.frame.size.width * 2;
int h = self.frame.size.height * 2;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate
(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);
CGContextDrawImage(context, CGRectMake(0, 0, w, h), imgV.CGImage);
CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 1);
char* text = (char *)[text1 cStringUsingEncoding:NSASCIIStringEncoding];
CGContextSelectFont(context, "Arial", 24, kCGEncodingMacRoman);
// Adjust text;
CGContextSetTextDrawingMode(context, kCGTextInvisible);
CGContextShowTextAtPoint(context, 0, 0, text, strlen(text));
CGPoint pt = CGContextGetTextPosition(context); …Run Code Online (Sandbox Code Playgroud)