Questions tagged [core-graphics]

Core Graphics is Apple's framework for low-level drawing operations on Mac OS X and iOS.

Core Graphics is Apple's framework for low-level drawing operations on macOS () and iOS ().

The term "Core Graphics" can actually apply to multiple frameworks. If your question is about any CG class, regardless of which framework it came from, then it is a Core Graphics question. For example, questions about CGImageSource (from ImageIO.framework) are as much Core Graphics questions as questions about CGContext (from CoreGraphics.framework) are.

Quartz 2D is part of Core Graphics, as it includes most of the CG classes (including CGContext). Note that there is another “Quartz”, which is a job scheduler for Java applications; the tag refers to that Quartz, not Quartz 2D.

References:

4660 questions
355
votes
16 answers

How do I draw a shadow under a UIView?

I'm trying to draw a shadow under the bottom edge of a UIView in Cocoa Touch. I understand that I should use CGContextSetShadow() to draw the shadow, but the Quartz 2D programming guide is a little vague: Save the graphics state. Call the function…
Fraser Speirs
  • 4,602
  • 3
  • 19
  • 15
219
votes
26 answers

invalid context 0x0 under iOS 7.0 and system degradation

I've read as many search results I could find on this dreaded problem, unfortunatelly, each one seems to focus on a specific function call. My problem is that I get the same error from multiple functions, which I am guessing are being called back…
Ælex
  • 12,734
  • 13
  • 75
  • 121
203
votes
11 answers

How to get pixel data from a UIImage (Cocoa Touch) or CGImage (Core Graphics)?

I have a UIImage (Cocoa Touch). From that, I'm happy to get a CGImage or anything else you'd like that's available. I'd like to write this function: - (int)getRGBAFromImage:(UIImage *)image atX:(int)xx andY:(int)yy { // [...] // What do I want…
Olie
  • 23,933
  • 18
  • 92
  • 129
188
votes
16 answers

UIImage: Resize, then Crop

I've been bashing my face into this one for literally days now and even though I feel constantly that I am right on the edge of revelation, I simply cannot achieve my goal. I thought, ahead of time in the conceptual phases of my design, that it…
Carson C.
  • 2,344
  • 4
  • 18
  • 20
186
votes
7 answers

Draw a perfect circle from user's touch

I have this practice project that allows the user to draw on the screen as they touch with their fingers. Very simple App I did as an exercise way back. My little cousin took the liberty of drawing things with his finger with my iPad on this App…
Unheilig
  • 15,690
  • 193
  • 65
  • 96
182
votes
18 answers

CGContextDrawImage draws image upside down when passed UIImage.CGImage

Does anyone know why CGContextDrawImage would be drawing my image upside down? I am loading an image in from my application: UIImage *image = [UIImage imageNamed:@"testImage.png"]; And then simply asking core graphics to draw it to my…
rustyshelf
  • 44,085
  • 36
  • 96
  • 104
182
votes
19 answers

How to Rotate a UIImage 90 degrees?

I have a UIImage that is UIImageOrientationUp (portrait) that I would like to rotate counter-clockwise by 90 degrees (to landscape). I don't want to use a CGAffineTransform. I want the pixels of the UIImage to actually shift position. I am using a…
RexOnRoids
  • 13,842
  • 33
  • 94
  • 134
148
votes
19 answers

Get Slightly Lighter and Darker Color from UIColor

I was looking to be able to turn any UIColor into a gradient. The way I am intending to do this is by using Core Graphics to draw a gradient. What I am trying to do is to get a color, lets say: [UIColor colorWithRed:0.5 green:0.5 blue:0.5…
CoreCode
  • 2,177
  • 4
  • 18
  • 24
143
votes
4 answers

to drawRect or not to drawRect (when should one use drawRect/Core Graphics vs subviews/images and why?)

To clarify the purpose of this question: I know HOW to create complicated views with both subviews and using drawRect. I'm trying to fully understand the when's and why's to use one over the other. I also understand that it doesn't make sense to…
Bob Spryn
  • 17,394
  • 12
  • 65
  • 89
128
votes
8 answers

How to control shadow spread and blur?

I have designed UI elements in sketch, and one of them has a shadow with blur 1 and spread 0. I looked at the doc for the views layer property and layer doesn't have anything named spread or blur, or anything equivalent (the only control was merely…
Quantaliinuxite
  • 2,853
  • 3
  • 14
  • 28
121
votes
6 answers

How to create a colored 1x1 UIImage on the iPhone dynamically?

I would like to create a 1x1 UIImage dynamically based on a UIColor. I suspect this can quickly be done with Quartz2d, and I'm poring over the documentation trying to get a grasp of the fundamentals. However, it looks like there are a lot of…
Ian Terrell
  • 10,280
  • 10
  • 41
  • 65
113
votes
4 answers

How to store CGRect values in NSMutableArray?

How would I store CGRect objects in a NSMutableArray, and then later retrieve them?
113
votes
6 answers

iOS 7 style Blur view

Does anybody know of any controls that will replicate the iOS7 style blur views. I'm assumming there can be some kind of UIView subclass that will replicate the behavior. I'm talking about these type views which blur the background extremely…
endy
  • 3,824
  • 4
  • 26
  • 43
112
votes
15 answers

How do I make UILabel display outlined text?

All I want is a one pixel black border around my white UILabel text. I got as far as subclassing UILabel with the code below, which I clumsily cobbled together from a few tangentially related online examples. And it works but it's very, very slow…
Monte Hurd
  • 4,360
  • 5
  • 27
  • 34
93
votes
6 answers

NSLog with CGPoint data

I have a CGPoint called point that is being assigned a touch: UITouch *touch = [touches anyObject]; CGPoint point = [touch locationInView:self]; I want to get the x coordinate value into my console log: NSLog(@"x: %s", point.x); When I use this,…
Spanky
  • 4,800
  • 6
  • 33
  • 35
1
2 3
99 100