The CGContextRef opaque type represents a Quartz 2D drawing destination.
Questions tagged [cgcontext]
977 questions
10
votes
1 answer
: CGContextSaveGState: invalid context 0x0 Error
I am getting some issue related with preparing the UIImage out of a UIView. I sometimes (but not always) see the error
: CGContextSaveGState: invalid context 0x0
I'm using the iPhone SDK 4.0. My code:
-(void)drawRect:(CGRect)rect
{
//…

Sagar...
- 1,062
- 3
- 15
- 35
10
votes
2 answers
Using NSString's drawAtPoint method in place of CGContextShowGlyphsAtPoint problems
In my app I'm trying to render text along a path; this is fine for most characters but not for Japanese (or anything non mac-Roman). I've been advised to use [NSString drawAtPoint] which displays the correct characters in my CATiledLayer; however,…

davbryn
- 7,156
- 2
- 24
- 47
10
votes
1 answer
Clear image with fade border
I have two UIImageView with same frame. One imageView above second imageView now I'm erasing upper imageView using Core Graphics. My problem is that the border of eraser is very sharp I want faded border i.e. after erasing the upper image should…

TheTiger
- 13,264
- 3
- 57
- 82
9
votes
2 answers
How to draw String in CGContext?
I am trying to draw a string in the overriden draw method of CALayer (I'm programming for iOS).
override func draw(in ctx: CGContext) {
let font = UIFont.systemFont(ofSize: 30)
let string = NSAttributedString(string: "23", attributes:…

Melodius
- 2,505
- 3
- 22
- 37
9
votes
1 answer
How to render UIView into a CGContext
I Wanted to render a UIView into a CGContextRef
-(void)methodName:(CGContextRef)ctx {
UIView *someView = [[UIView alloc] init];
MagicalFunction(ctx, someView);
}
So, the MagicalFunction here is supposed to render the UIView(may be its…

SPatil
- 1,003
- 8
- 13
9
votes
2 answers
Create a UIImage by rendering UIWebView on a background thread - iPhone
Does someone know of a way, or has a creative idea as to how to obtain an UIImage that is rendered from a UIWebView? The catch is, that is must be on a background thread.
I'll elaborate:
I'm trying to obtain the image from multiple UIWebViews every…

Gilbert
- 868
- 8
- 14
9
votes
2 answers
Why does my CGContext-drawn circle suck?
I have a custom table view cell that is intended to draw a circle like the iPhone’s Mail.app does:
Instead, it draws like this:
Here’s my code:
CGContextRef context = UIGraphicsGetCurrentContext();
UIColor *grayColor = [UIColor…

Abraham Vegh
- 1,490
- 1
- 12
- 32
9
votes
1 answer
MapView overlay is cutting off after zoom in
I am facing a weird problem with MKMapView. I have used a MKOverlayRenderer. Now the problem is when I am zooming out image showing correctly. But in case of zoom in, some portion of the image are cutting off. It's looking like a portion of MapView…

Tapas Pal
- 7,073
- 8
- 39
- 86
9
votes
2 answers
iphone MPMoviePlayerViewController CGContext Errors
I am writing an app for the iPhone that will play some movies utilizing MPMoviePlayerViewController. So far I have gotten it to play movies, however it is throwing some errors in the debugger that all start with CGContext. I have wracked my brain…

Joseph
- 145
- 1
- 9
8
votes
2 answers
Using CGContext to draw line
I wanted to draw a line using CGContext and what I have so far is:
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
CGContextSetLineWidth(context,…

aherlambang
- 14,290
- 50
- 150
- 253
8
votes
2 answers
draw CALayer into a CGContext
I have the following code:
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CALayer *sublayer = [CALayer layer];
sublayer.backgroundColor = [UIColor orangeColor].CGColor;
sublayer.cornerRadius =…

lucas
- 443
- 1
- 5
- 11
8
votes
1 answer
iOS: 2 Step Image Processing with CoreGraphics
Using CoreGraphics (inside my drawRect method), I'm trying to apply a blend mode to an image (transparent png), and then adjust the alpha of the result. I'm assuming that this needs to be done in two steps, but I could be wrong. Here's what I have…

Chazbot
- 1,890
- 1
- 13
- 23
8
votes
1 answer
Drawing into CGImageRef
I want to create a CGImageRef and draw points to it.
What context to use to create an empty CGImageRef and be able to draw onto it.
CGContextRef or CGBitmapContextRef?
If you can provide code to create an empty CGImageRef image and draw to it I…

Cyprian
- 9,423
- 4
- 39
- 73
8
votes
6 answers
IOS: how to calculate the size of text to draw BEFORE to create the context?
I need to create an image containing one line of text. But the problem, i first need to create the context (CGBitmapContextCreate) with require the width and the height of the image to have the possibility to later calculate the bounds of the text…

zeus
- 12,173
- 9
- 63
- 184
8
votes
1 answer
When is -[UIView drawRect:] Method Invoked?
Is it invoked just before the main view is going to be shown
Can we call it whenever we want?

wolverine
- 2,967
- 5
- 31
- 35