Drawing around CGContextRef to remove pixelation

萝らか妹 提交于 2019-12-03 20:48:23

The pixelation is occurring because when you make the image context you don't take the screen scale into consideration. Your code should be something like this (note the 1st line):

UIGraphicsBeginImageContextWithOptions(cell.imageViewPic.bounds.size, NO, [UIScreen mainScreen].scale)
CGContextRef contextRef = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(contextRef, [[event calendar] CGColor]);
CGContextFillEllipseInRect(contextRef,(CGRectMake (0.f, 0.f, cell.imageViewPic.bounds.size.width, cell.imageViewPic.bounds.size.height)));

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
cell.imageViewPic.image = image;

Update: As someone commented, you can pass in 0 instead of [UIScreen mainScreen].scale. The docs agree:

The scale factor to apply to the bitmap. If you specify a value of 0.0, the scale factor is set to the scale factor of the device’s main screen.

This is the same answer as @Christian Di Lorenzo.. But this is shorter at more straight forward.

Change This:

UIGraphicsBeginImageContext(cell.imageViewPic.bounds.size);

To this:

UIGraphicsBeginImageContextWithOptions(cell.imageViewPic.bounds.size, NO, [UIScreen mainScreen].scale);

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!