Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can do this using Core Graphics/Quartz 2D. I'm not too experienced with Core Graphics myself, but check out the documentation here that describes loading a graphic context with an image, which you can then save out to a file after modifying, or just drawing an image from scratch and saving it out:</p> <p>Link 1: <a href="http://developer.apple.com/library/ios/#documentation/2ddrawing/conceptual/drawingprintingios/HandlingImages/Images.html#//apple_ref/doc/uid/TP40010156-CH13-SW1" rel="nofollow" title="Drawing/Printing iOS">Drawing/Printing for iOS</a></p> <p>Link 2: <a href="https://developer.apple.com/library/ios/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/Introduction/Introduction.html#//apple_ref/doc/uid/TP30001066" rel="nofollow" title="Quartz 2D Programming Guide">Quartz 2D Programming Guide</a></p> <p>Quick example of drawing text from the <a href="https://developer.apple.com/library/ios/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_text/dq_text.html#//apple_ref/doc/uid/TP30001066-CH213-TPXREF101" rel="nofollow" title="Quartz 2D Programming Guide - Text">Quartz 2D Programming Guide</a> under the "Text" section:</p> <pre><code>void MyDrawText (CGContextRef myContext, CGRect contextRect) // 1 { float w, h; w = contextRect.size.width; h = contextRect.size.height; CGAffineTransform myTextTransform; // 2 CGContextSelectFont (myContext, // 3 "Helvetica-Bold", h/10, kCGEncodingMacRoman); CGContextSetCharacterSpacing (myContext, 10); // 4 CGContextSetTextDrawingMode (myContext, kCGTextFillStroke); // 5 CGContextSetRGBFillColor (myContext, 0, 1, 0, .5); // 6 CGContextSetRGBStrokeColor (myContext, 0, 0, 1, 1); // 7 myTextTransform = CGAffineTransformMakeRotation (MyRadians (45)); // 8 CGContextSetTextMatrix (myContext, myTextTransform); // 9 CGContextShowTextAtPoint (myContext, 40, 0, "Quartz 2D", 9); // 10 } </code></pre> <p>Here’s what the code does:</p> <ol> <li>Takes as parameters a graphics context and a rectangle to draw to.</li> <li>Declares storage for the affine transform.</li> <li>Sets the font to Helvetica and the font size to the height of the page rectangle divided by 10. The font size is in text space units. In this example, the text is drawn to a resizable window. When the user resizes the window, the text resizes as well. The encoding is set to kCGEncodingMacRoman, but the only other choice is kCGEncodingFontSpecific.</li> <li>Sets the character spacing to 10 text space units. You call this function only if you want to add the additional space to the advance between the origin of one glyph and the origin of the next glyph.</li> <li>Sets the text drawing mode to fill and stroke.</li> <li>Sets the fill color to green with an alpha value of .5 for a partially transparent fill. Note that this is not a text-specific attribute. The fill color applies to the graphics state.</li> <li>Sets the stroke color to opaque blue. This is another attribute that is not text specific.</li> <li>Creates an affine transform that performs a 45 degree rotation. The MyRadians routine is an application-defined convenience function for computing degrees from radians. You either need to supply your own routine to convert degrees to radians, or you need to substitute this call with a value that specifies radians. Otherwise, this code example will not compile.</li> <li>Sets the text matrix to the transform created in the last step.</li> <li>Draws the text, passing the x and y coordinates in text space to start the drawing at (40,0), an array of characters to draw, and a value that specifies the length of the text array. In this case, you pass a C-style string and the value 9 to specify the number of characters.</li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload