I’m trying to understand the coordinate system of 2d quartz, I am currently reading the Apple reference book and the old book “Quartz 2d graphics for mac os x developer”.
I understand the concept of the concept of "space-space" and "device-space", that the device space can have different coordinates by default and the coordinates of the space-device can not be changed, and we display the user space by changing its coordinate system, connecting to the device- space to achieve the desired result.
- First part of the problem
Quartz 2d graphics for Mac OS X Developer book say:
When transforming the coordinate system , you must have another one to compare it with. The transformation provides a relative mapping from one coordinate system to another. When you draw in a transformed coordinate system, the transformation displays a return to the first coordinate system . The appearance of this On the graph in a fixed coordinate system, the transformation affects.
I did not get this highlighted in bold.
and
Quartz 2D Programming Guide says:
Quartz performs device independence with a separate coordinate system-user space — mapping it to the output coordinate system of the device-device space — using the current transformation matrix or CTM. a matrix is ​​a mathematical construct used to effectively describe a set of related equations. The current transformation matrix is ​​a specific type of matrix called an affine transformation that maps points from one coordinate space to another using translation, rotation, and scaling (calculations that move, rotate, and change the size of the coordinate system).
The current transformation matrix has a secondary purpose: it allows you to convert objects to objects. For example, to draw a box rotated 45 degrees, you rotate the page coordinate system (CTM) before you draw a window. Quartz accesses the output device using a rotating coordinate system.
The confusion is that "quartz refers to the output device using a rotated coordinate system." If I want one object (image, etc.) to rotate, and the other without rotation, then what will happen? We have whole coordinates rotating, will each figure be rotated?
I try different experiments, but I can’t wrap this topic around myself, create an image that draws two lines, replicating the lower left coordinate system in Photoshop, and then added to my project to see how the coordinates behave, calling CGContextRotateCTM(myContext, 45);
in the drawrect method, but it did nothing for the image that I included in the xib file using an interface constructor that places the image inside uiimage.
this code is from the quartz two-dimensional programming guide
CGContextRef myContext = UIGraphicsGetCurrentContext(); CGRect contextRect = self.bounds; CGContextTranslateCTM(myContext, 0, contextRect.size.height); CGContextRotateCTM(myContext, 45);
but does this code change the text drawn on the screen, and not the image that I added?
- Second part of the problem
This is also from the 2D quartz programming guide:
... apply a transformation that translates the beginning to the upper left corner of the PDF context and scales the y-coordinate by -1.
Using a scaling transform to negate the y coordinate changes some conventions in the quartz drawing. For example, if you call CGContextDrawImage to draw an image in context, the image is modified by the transformation when it is pulled to the destination ....
I already do this -1 thing, but I don’t affect the image, and this -1 thing is still not clear to me.
I have read this document several times, tried google search, but not a useful tutorial, and also no books are available, only books written in 2004, 2005, 2006 are available. Can anyone help with this, or can they send me useful resources to study this in depth.
Desperate for answers, I really need help. Thanks.