Questions tagged [core-graphics]

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

core-graphics
Filter by
Sorted by
Tagged with
358 votes
16 answers
258k views

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 ...
Fraser Speirs's user avatar
219 votes
26 answers
87k views

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 ...
Ælex's user avatar
  • 14.6k
205 votes
11 answers
151k views

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)...
Olie's user avatar
  • 24.7k
190 votes
17 answers
124k views

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 ...
Carson C.'s user avatar
  • 2,372
187 votes
18 answers
127k views

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 ...
rustyshelf's user avatar
186 votes
8 answers
9k views

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 ...
Unheilig's user avatar
  • 16.2k
184 votes
19 answers
192k views

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 ...
RexOnRoids's user avatar
151 votes
19 answers
63k views

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: [...
CoreCode's user avatar
  • 2,227
143 votes
4 answers
19k views

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 ...
Bob Spryn's user avatar
  • 17.8k
140 votes
8 answers
82k views

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 ...
Quantaliinuxite's user avatar
121 votes
6 answers
39k views

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. ...
Ian Terrell's user avatar
  • 10.8k
120 votes
15 answers
75k views

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 ...
Monte Hurd's user avatar
  • 4,399
114 votes
4 answers
27k views

How to store CGRect values in NSMutableArray?

How would I store CGRect objects in a NSMutableArray, and then later retrieve them?
Krishna Chaitanya Bandaru's user avatar
113 votes
6 answers
66k views

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 ...
endy's user avatar
  • 3,872
102 votes
8 answers
135k views

Where can I find a list of Mac virtual key codes?

I'm using CGEventCreateKeyboardEvent and need to know what CGKeyCode values to use. Specifically, I am after the key code for the Command key. The docs give examples for other keys: z is 6, shift is ...
Nick Moore's user avatar
  • 15.7k
95 votes
4 answers
76k views

How can I set CG_CONTEXT_SHOW_BACKTRACE environmental variable?

I have three buttons in my view. After setting the cornerRadus in the viewDidLoad() : button.layer.cornerRadius = 20 I get the following error message in the log: <Error>: CGContextSaveGState: ...
user avatar
93 votes
7 answers
44k views

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 ...
Spanky's user avatar
  • 4,990
92 votes
13 answers
38k views

Get lighter and darker color variations for a given UIColor

How to get different lighter and darker variations of a given UIColor in Swift?
Stephen's user avatar
  • 3,405
92 votes
17 answers
86k views

Inner shadow effect on UIView layer?

I have the following CALayer: CAGradientLayer *gradient = [CAGradientLayer layer]; gradient.frame = CGRectMake(8, 57, 296, 30); gradient.cornerRadius = 3.0f; gradient.colors = [NSArray ...
runmad's user avatar
  • 14.9k
91 votes
7 answers
58k views

How to Convert UIView to PDF within iOS?

There are a lot of resources about how to display a PDF in an App's UIView. What I am working on now is to create a PDF from UIViews. For example, I have a UIView, with subviews like Textviews, ...
Cullen SUN's user avatar
  • 3,527
80 votes
6 answers
59k views

Extracting rgb from UIColor [duplicate]

Seen this asked before but my example does not seem to work. const CGFloat *toCol = CGColorGetComponents([[UIColor greenColor] CGColor]); The array is empty from looking at it with GDB. Any hints?
user avatar
80 votes
5 answers
39k views

How to draw a smooth circle with CAShapeLayer and UIBezierPath?

I am attempting to draw a stroked circle by using a CAShapeLayer and setting a circular path on it. However, this method is consistently less accurate when rendered to the screen than using ...
bcherry's user avatar
  • 7,170
79 votes
6 answers
35k views

iOS: what's the fastest, most performant way to make a screenshot programmatically?

in my iPad app, I'd like to make a screenshot of a UIView taking a big part of the screen. Unfortunately, the subviews are pretty deeply nested, so it takes to long to make the screenshot and animate ...
swalkner's user avatar
  • 16.9k
79 votes
3 answers
35k views

What's the difference between Quartz Core, Core Graphics and Quartz 2D?

I wonder if someone can distinguish precisely between these? For my understanding, Core Graphics is just a "Framework Package" which contains Quartz Core and Quartz 2D. But I'm not sure about if ...
openfrog's user avatar
  • 40.4k
79 votes
4 answers
34k views

NSAttributedString background color and rounded corners

I have a question regarding rounded corners and text background color for a custom UIView. Basically, I need to achieve an effect like this (image attached - notice the rounded corners on one side) ...
codeBearer's user avatar
  • 5,164
77 votes
8 answers
71k views

How to Convert UIImage to CIImage and vice versa

I'm trying to get CIImage from ImageView that display on the screen. UIImage *image = myImageView.image; convert image UIImage to CIImage. CIImage *cImage = [....]; How to do this?
HelmiB's user avatar
  • 12.3k
77 votes
9 answers
68k views

How to scale down a UIImage and make it crispy / sharp at the same time instead of blurry?

I need to scale down an image, but in a sharp way. In Photoshop for example there are the image size reduction options "Bicubic Smoother" (blurry) and "Bicubic Sharper". Is this image downscaling ...
Proud Member's user avatar
  • 40.3k
75 votes
3 answers
34k views

Draw segments from a circle or donut

I've been trying to figure out a way to draw segments as illustrated in the following image: I'd like to: draw the segment include gradients include shadows animate the drawing from 0 to n angle I'...
Chris Baxter's user avatar
  • 1,456
74 votes
3 answers
40k views

Create and export an animated gif via iOS?

I have a series of user-customized images within an iOS app that are being animated in a simple, frame-by-frame flip book style. My question is this: is there a way to allow users to export their ...
crgt's user avatar
  • 1,482
67 votes
2 answers
2k views

Detecting CGAssociateMouseAndMouseCursorPosition

We're making a user-space device driver for OS X that moves the cursor using Quartz Events, and we ran into a problem when games — especially ones that run in a windowed mode — can't properly capture ...
Dae's user avatar
  • 2,365
66 votes
9 answers
84k views

How to draw a rounded rectangle in Core Graphics / Quartz 2D?

I need to draw an outline for a rounded rectangle. I know I can make lines and arcs, but maybe there is also a function for rounded rects?
dontWatchMyProfile's user avatar
64 votes
6 answers
42k views

iPhone smooth sketch drawing algorithm

I am working on a sketching app on the iPhone. I got it working but not pretty as seen here And I am looking for any suggestion to smooth the drawing Basically, what I did is when user places a ...
Suwitcha Sugthana's user avatar
61 votes
7 answers
48k views

How to merge two UIImages?

I am trying to merge two different images and create a new one. This is the way I would like to do: I have this image (A): It's a PNG image and I would like to merge this one with another image (B) ...
Luca Alberto's user avatar
  • 1,235
59 votes
16 answers
36k views

Getting a screenshot of a UIScrollView, including offscreen parts

I have a UIScrollView decendent that implements a takeScreenshot method that looks like this: -(void)takeScreenshot { CGRect contextRect = CGRectMake(0, 0, 768, 1004); ...
Tim Sullivan's user avatar
  • 16.9k
57 votes
11 answers
53k views

Rounded Corners only on Top of a UIView

Hi i am searching a clean solution without overwriting drawRect or stuff like that to create a UIView with Rounded corners on the Top of the View. My main problem here is to create variable solution ...
mariusLAN's user avatar
  • 1,205
57 votes
1 answer
10k views

What's the difference and compatibility of CGLayer and CALayer?

I'm confusing CGLayer and CALayer. They look similar, so why are there separate implementations? What's the difference between, and compatibility of, CGLayer and CALayer?
eonil's user avatar
  • 84.7k
57 votes
9 answers
40k views

Problem setting exif data for an image

I'm using the new ImageIO framework in iOS 4.1. I successfully retrieve the exif metadata using the following: CFDictionaryRef metadataDict = CMGetAttachment(sampleBuffer, ...
akaru's user avatar
  • 6,299
56 votes
5 answers
19k views

How to detect where NaN is passing to CoreGraphics API on Mac OS X 10.9

I have very large graphic Mac app and now I receive a lot of the following messages in Console on 10.9 GM. <Error>: Error: this application, or a library it uses, has passed an invalid numeric ...
Igor's user avatar
  • 930
55 votes
16 answers
72k views

Create a rectangle with just two rounded corners in swift?

I need to create a rectangle that have just two rounded corners in swift (Objective C code also ok). At the moment my code is creating two rectangles with CGPathCreateWithRoundedRect(CGRectMake(0, ...
Maralc's user avatar
  • 896
55 votes
12 answers
29k views

Curve text on existing circle

For an application I am building I have drawn 2 circles. One a bit bigger than the other. I want to curve text between those lines, for a circular menu I am building. I read most stuff about curving ...
Wim Haanstra's user avatar
  • 5,958
55 votes
3 answers
23k views

Get PDF hyperlinks on iOS with Quartz

I've spent all day trying to get hyperlinks metadata from PDFs in my iPad application. The CGPDF* APIs are a true nightmare, and the only piece of information I've found on the net about all this is ...
ySgPjx's user avatar
  • 10.2k
53 votes
4 answers
71k views

How do I create a CGRect from a CGPoint and CGSize?

I need to create a frame for a UIImageView from a varying collection of CGSize and CGPoint, both values will always be different depending on user's choices. So how can I make a CGRect form a CGPoint ...
inorganik's user avatar
  • 25k
53 votes
1 answer
13k views

What does yellow tinting represent when using "color misaligned images" on iPhone/iOS

so--i switched on "color misaligned images" to improve drawing performance in our app. The documentation states: Puts a magenta overlay over images whose source pixels aren't aligned to ...
nielsbot's user avatar
  • 16k
53 votes
1 answer
2k views

Weak performance of CGEventPost under GPU load

We've stumbled upon a performance problem with Quartz Events, more specifically CGEventPost: during heavy GPU load CGEventPost can block. We've created a small benchmark application to demonstrate the ...
Dae's user avatar
  • 2,365
51 votes
1 answer
6k views

CABasicAnimation does not animate correctly when I update model layer

I'm currently implementing a CABasicAnimation that animates a CALayer transform property. Now, although I'm new to Core Animation, I have been able to gather through various blogs and articles such as ...
user3546182's user avatar
49 votes
1 answer
3k views

How to use kCGImagePropertyGIFImageColorMap or create a color table?

I'm trying to tinker with a couple GIF properties such as kCGImagePropertyGIFImageColorMap and kCGImagePropertyGIFHasGlobalColorMap (reference) in Core Graphics. I'm creating animated GIFs and I'd ...
user339946's user avatar
  • 6,049

1
2 3 4 5
120