core-graphics

Measure dimensions of biggest character in a CGFont

谁说我不能喝 提交于 2019-12-23 16:55:06
问题 I am using CoreAnimation to build a view consisting of several layer which will be animated later on. There are also CATextLayer s which will contain only one character of a given font in a given size. To make it pretty I would like to set the bounds of the layer so that the character fits in neatly. The problem is that I have to determine the size of the biggest character in a CGFont which will be the basis of the bounds calculation for the text layer. In this question on SO measure size of

Must I multiply the scale with the point values for retina display, in this case?

半世苍凉 提交于 2019-12-23 12:07:17
问题 Since the retina display, suddenly this piece of drawing code seems to not work anymore. The drawn image is slightly offset than it was before and appears somewhat stretched. I am drawing something in the -drawRect: method of an UIControl subclass. I figured out that the current scale inside that UIControl indeed is 2.0. This code obtains an CGImage from an UIImage, which probably won't know anything about the scale. It's feeded as parameter to an method that also takes some point values

Adding outline/stroke to UITextView

北城以北 提交于 2019-12-23 10:06:10
问题 I want to add an outline or stroke to an editable UITextView text as the user types. Exactly like memes : http://t.qkme.me/3oi5rs.jpg I have to use a UITextView since I need multi line support. I have tried all the approaches and reached the conclusion that I must use CoreText . I got almost all of the solution working but got stuck at a point where the text in textview wraps. My drawRect routine in the subview of UITextView correctly draws the outline text until the text wraps. Even when the

Obtain a CGContextRef of NSView outside of drawRect?

て烟熏妆下的殇ゞ 提交于 2019-12-23 09:38:49
问题 I need to get CGContextRef of NSView object. It won't be so bad if I knew how. In Carbon this thing was done like this: CGContextRef cgref = (libvlc_drawable_t)GetWindowPort(HIViewGetWindow((OpaqueControlRef*)hiViewRef)); Obviously it can be done by subclassing NSView (or it's subclass) and catching it in it's drawRect, but that's too ugly. Your ideas? 回答1: I've never used it but it think this is your way: [myView lockFocus]; imageContext = (CGContextRef)[[NSGraphicsContext currentContext]

CGPath with outline

断了今生、忘了曾经 提交于 2019-12-23 07:47:02
问题 I am trying to draw a CGPath that has a stroke for it's stroke. Basically I want a draw a line using CGPath. I then want to go back and draw lines on both sides of the last CGPath giving it the effect that it is outlines. This line can bend and turn in any way but I always need the two lines on the outside to follow. EDIT: I need to be able to make the middle of the line transparent but the outlines solid black. 回答1: Use CGPathCreateCopyByStrokingPath to create a new path by stroking your old

iPhone : How to get colour of each pixel of an image?

依然范特西╮ 提交于 2019-12-23 05:36:06
问题 I want to get color of all the individual pixels of an image. To elaborate Let say I have an image named "SampleImage" having 400 x 400 pixels Basically I want to create a grid from 'SampleImage' which will have 400 x 400 squares each filled with color corresponding to the specific pixel in 'SampleImage'. I know this is a little abstract, but I am novice in iOS and don't know where to start from. Thanks in advance! 回答1: Use this : Here is more efficient solution: // UIView+ColorOfPoint.h

PDF Highlighting above image / below text

家住魔仙堡 提交于 2019-12-23 05:15:27
问题 i'm trying to highlight text in a pdf, and have the highlighted rectangle to be drawn under the text. It works fine on most PDF's, but I jumped into a problem when the text I'm trying to highlight has an image/background under it. The problem is that the highlight rectangle is drawn under the image as well, so it is not visible. The drawing order I have is this: draw a blank rectangle with the page size draw the highlight draw the pdf using CGContextDrawPDFPage(context, page); Is there a way

Scratch Card effect in Swift 3

泪湿孤枕 提交于 2019-12-23 04:52:58
问题 I am trying to implement a Scratch Card effect in Swift 3 for my app, I found some examples but they're on Objective C (show scratch-card effect with the help of using scratch and win example) In essence user swipes with finger on an image and reveals another image below their finger as they swipe. Any one knows how to do this in Swift 3? Any help greatly appreciated 回答1: You can use ScratchCard library. It has simple API, but I don't know is it Swift 3 compatible. Anyway, you can rewrite it

How to fill space between two UIBezierPaths

烈酒焚心 提交于 2019-12-23 04:28:16
问题 I'm working on drawing application which provides drawing lines with variable line width which depends on drawing speed. This behavior inspired by Paper app. Algorithm which I'm trying to implement -- draw two bezier path with variable distance between them. The solution which described in sosborn's answer. Then smooth paths and fill the distance between them. Actually I don't figured out how to fill space between paths. 回答1: You create a single path from the 2 bezier curves and fill it, like

How to implement a Photoshop Curves editor in UIKit

旧城冷巷雨未停 提交于 2019-12-23 04:04:28
问题 I'm familiar with UIBezierPath and the corresponding CG routines, but none of them appear to draw the same type of path as what I see in Photoshop, etc. How would one go about this? I'm just talking about the UI--letting the user drag around points. A java example I found is here: http://www.cse.unsw.edu.au/~lambert/splines/natcubic.html 回答1: I would look into CGContextAddCurveToPoint and drag around curve's control points. If you require more control points to create a complex curve, just