Scaling iPhone "Vector Graphics" on Affine Transforms

I made a "circle" with this drawRect

- (void)drawRect:(CGRect)rect { CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(ctx, color.CGColor); CGContextAddEllipseInRect(ctx, rect); CGContextFillPath(ctx); } 

When I try to scale the view up using CGAffineTransformMakeScale(2.0, 2.0) , the result will be blurry and pixelated at the edges. However, the programming guide says that Quartz uses vector commands to draw representations and that they will continue to look good when using affine transforms:

The quartz drawing system uses a vector drawing model. Compared to a raster-based drawing model in which drawing commands work with individual pixels, the drawing commands in Quartz are set using a fixed-scale drawing space, known as the user coordinate space. iPhone OS then maps the coordinates in this drawing space to the actual pixels of the device. The advantage of this model is that graphics drawn using vector commands continue to look good when scaling up or down using the affine transform .

Or am I not using vector commands? If not, how would you do this to draw a circle?

Thanks.

+4
source share
3 answers

Applying a transform to a view does not redraw it. All he does is scale the view layer, which is a raster texture stored on the GPU. This will result in blurry graphics.

When drawing on iPhone, -drawRect: displayed to provide content for the view layer. This content is then cached as a texture on the GPU.

What they refer to in the manual is a conversion application during -drawRect: when vector graphics are drawn. If you use the transformation there (via CGContextConcatCTM() or the like), the circle will be drawn smoothly on a larger scale. However, you also need to resize your view to reflect this large figure. I recommend using the scale property in your custom view subclass, which you can set to a different scale factor that will handle resizing and drastic changes in its contents.

+5
source

It depends on when I apply the scaling transform. If you draw it first, then do a scale transformation, then it will look jagged (because it was scaled after drawing). If you scale before you perform the drawing procedure, I expect it to work as expected.

So, you use vector commands to achieve this; I suspect this is an order issue. When do you do the conversion and drawing?

0
source

You can try calling setNeedsDisplay after the conversion, I'm not sure if this will work or not, but it's worth it.

0
source

Source: https://habr.com/ru/post/1299826/


All Articles