core-graphics

iOS CoreGraphics: Draw arc, determine arc angles from intersecting chord theorem

强颜欢笑 提交于 2019-12-06 02:23:44
问题 I'm trying to figure out how to draw an arc in CoreGraphics. I understand which method calls to make and how to compute the angles in the following scenario. ---------- | | *--------* When the points are both in the bottom of the rect. However when two points are in other locations, I don't know how to calculate the correct angle. ---------* | | *--------- See bottom portion of my image. Ray Wenderlich has a great tutorial about creating arcs for only in the first mentioned point positions. /

how to traverse window/view hierarchy of other application in OS X?

一个人想着一个人 提交于 2019-12-06 00:16:35
I am trying to figure out how to get(read only) entire window/view hierarchy of any application. I get list of all open windows using "CGWindowListCopyWindowInfo" . It also returns window number( "kCGWindowNumber" ). It also shows sharing status of root window by "kCGWindowSharingState = 1;" . Now, I want to check that a particular window/view present in hierarchy of that application. I got kCGWindowNumber which is root window of application. This is now possible via the View Debugging features of Xcode. To use this: Start the target app running as you normally would Launch Xcode, and open a

Core Text in Cocoa app

时光怂恿深爱的人放手 提交于 2019-12-06 00:12:32
I have the following sample code which works on iPhone. It draws the text "Hello World!" on the screen using Core Text. Dropping this code into a cocoa project in an NSView produces different results. The font size is scaled much bigger and the letters are drawn on top of each other. How do I have the text draw the same in the cocoa app? - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSaveGState(context); CFStringRef font_name = CFStringCreateWithCString(NULL, "Courier", kCFStringEncodingMacRoman); CTFontRef font = CTFontCreateWithName(font_name,

Core Graphics & GIF Color Table

断了今生、忘了曾经 提交于 2019-12-05 23:55:40
问题 I am trying to limit the number of colors of an animated GIF (created from an array of CGImageRef ). However, I am have difficulty actually setting the custom color table. Does anyone know how to do this with Core Graphics? I know of kCGImagePropertyGIFImageColorMap . Below is some test code (borrowing heavily from this github gist -- since it's the only instance of kCGImagePropertyGIFImageColorMap Google could find). NSString *path = [@"~/Desktop/test.png" stringByExpandingTildeInPath];

What does CGColorGetComponents() return?

允我心安 提交于 2019-12-05 23:23:02
问题 CGFloat* colors = CGColorGetComponents(hsbaColor.CGColor); Does this return a float, or an array of floats? It looks like the asterisk is shorthand for creating an array. Is that correct? When I call this function on the CGColor property of an HSB UIColor object does it convert the values to RGB? 回答1: Yes, it returns an array of CGFloats . Specifically, it returns "an array of intensity values for the color components (including alpha) associated with the specified color." The color

renderInContext creating memory that is not promptly released

Deadly 提交于 2019-12-05 21:24:47
While debugging in instruments using 'ObjectAlloc' I'm noticing 7megs of memory being allocated for the renderInContext call, but it never is released. When I comment out the renderInContext call this doesn't happen, and future renderInContext calls does not continue to increase the memory allotment. UIGraphicsBeginImageContext(contentHolder.bounds.size); [contentHolder.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); Is there a way to force this memory to be released? I found out how to release

How to draw a UILabel with a different blend mode in draw(_ rect: CGRect) in Swift

跟風遠走 提交于 2019-12-05 21:07:30
So I have a UILabel that is being drawn on top of a gradient image (that is a UIImageView ). It looks sorta like this: I'm trying to change the blendMode of the graphics context in the UILabel 's draw(_ rect: CGRect) function so that it draws the label but blended with the background with a softLight blending mode. Here is what I want it to look like: Here is the code I have in the draw(_ rect: CGRect) function: override func draw(_ rect: CGRect) { // Drawing code if let context = UIGraphicsGetCurrentContext() { context.setBlendMode(.softLight) self.textColor.set() self.drawText(in: rect) } }

Sibling NSView z-ordering in Cocoa

↘锁芯ラ 提交于 2019-12-05 19:29:27
How does z-ordering work with sibling NSViews in Cocoa? I'm confused because I'm finding conflicting sources of information in Apple's docs and APIs. (Note: Subviews are obviously rendered on top of its parent view, I am talking explicitly about sibling views here). Hypothesis A : "Yes, you can define the z-order of sibling NSViews " In IB you can place views on top of each other and they will always be composited in the way you'd expect. There's buttons in Xcode under the Editor menu named "Send to Back", "Send Forward" etc. The NSView also has a method named - (void)addSubview:(NSView *

Drawing simple lines on iPhone with CoreGraphics

无人久伴 提交于 2019-12-05 18:39:35
问题 I would like to draw a straight line between where a user touches the screen, and where the touch ends. i need multiple lines, for if the user repeats the touch-drag-release action, and I also need a button to clear all of the lines. So far I have this code below, but once it is called again, I receive the errors: CGContextSetStrokeColor: invalid context 0x0. This error repeats for: CGContextBeginPath, CGContextMoveToPoint, CGContextAddLineToPoint, CGContextDrawPath. Any ideas? - (void

Get Image back from CGBitmapContextGetData

岁酱吖の 提交于 2019-12-05 18:34:53
So I have a CGBitmapContext and I get the pixel at a touchlocation using this unsigned char* data = CGBitmapContextGetData (offscreenBuffer); if (data != NULL) { offset = 4*((self.bounds.size.width*round(coord.y))+round(coord.x)); int alpha = data[offset]; int red = data[offset+1]; int green = data[offset+2]; int blue = data[offset+3]; } And then I change the pixel colour like below. data[offset]=255; data[offset+1]=255; data[offset+2]=0; data[offset+3]=0; My question is how do a get a CGImage back from the modified pixels so that I can update my CGBitmapContext ? Any help will be appreciated,