The CGContextRef opaque type represents a Quartz 2D drawing destination.
Questions tagged [cgcontext]
977 questions
8
votes
4 answers
Remove alpha channel from UIImage
I use the following method to get a decompressed uiimage from file system. However the UIImageView is colored as red when I turn on the color blended layer, even though the UIImageView is set to Opaque.
The images on file system don't have alpha…

Jensen
- 1,653
- 4
- 26
- 42
8
votes
3 answers
Drawing a polygon with one color for stroke, and a different one for fill?
I'm having trouble with drawing some lines that are stroked with a color and then filling their insides (they make a polygon) with another one.
UIColor *houseBorderColor = [UIColor colorWithRed:(170/255.0) green:(138/255.0) blue:(99/255.0)…

Morgan Wilde
- 16,795
- 10
- 53
- 99
8
votes
4 answers
Iphone CGContextShowTextAtPoint for Japanese characters
I am working on an app where I am using CGContextShowTextAtPoint to display text to the screen. I want to also display Japanese characters, but CGContextShowTextAtPoint takes as its input a C string. So either A) How do I change Japanese characters…

kiyoshi
- 837
- 1
- 8
- 20
8
votes
3 answers
How can I render line faster than CGContextStrokePath?
I'm plotting ~768 points for a graph using CGContextStrokePath. The problem is that every second I get a new data point, and thus redraw the graph. This is currently taking 50% CPU in what's already a busy App.
Graph drawing is done in drawRect…

Peter
- 398
- 3
- 20
7
votes
3 answers
How to take high-quality screenshot with UIGraphicsImageRenderer programmatically?
PROBLEM: After I take screenshot the image is blurry when check by zooming. The text inside image seems to be blurred when zoomed.
I know this question have been raised many a times but none of them have desired solution. I already checked quite a…

Parvez Belim
- 1,003
- 13
- 36
7
votes
2 answers
How to get rid of this "points" between my lines when I am drawing?
is there an easy way to not draw this points in my lines?
I don't know why this points are there because i never release my finger from screen during drawing of a line.
I got the code from a drawing example.
// draw a line
-…

madmax
- 1,803
- 3
- 25
- 50
7
votes
2 answers
Crazy rounded rect UIBezierPath behavior on iOS 7. What is the deal?
The simple UIView below draws a rounded rectangle. When I pass a corner radius of 65 or below it rounds correctly, but 66 and above and it generates a perfect circle! What is going on here? It should only show a circle when the corner radius is…

Steveo
- 2,238
- 1
- 21
- 34
7
votes
3 answers
How can I reset or clear the clipping mask associated with a CGContext?
I'm drawing to a CGContext and using a CGImageRef-based mask:
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClipToMask(context, rect, _firstMaskImageRef);
CGContextSetFillColorWithColor(context, color);
CGContextFillRect(context,…

WiseOldDuck
- 3,156
- 2
- 24
- 27
7
votes
1 answer
CGContextAddArc counterclockwise instead of clockwise
I'm having an issue when drawing an arc inside of my drawing function inside of a CALayer subclass. The implementation for that drawing function is as follows:
-(void)drawInContext:(CGContextRef)ctx
{
CGPoint center =…

J Kagney
- 239
- 1
- 4
- 9
7
votes
4 answers
Quartz2D: How to convert a clipping rect to an inverted mask at runtime?
Given:
a CGContextRef (ctx) with frame {0,0,100,100}
and a rect (r), with frame {25,25,50,50}
It's easy to clip the context to that rect:
CGContextClipToRect(ctx, r);
to mask out the red area below (red == mask):
But I want to invert this…

Todd Ditchendorf
- 11,217
- 14
- 69
- 123
7
votes
1 answer
Drawing a dashed line with CGContextSetLineDash
I'm trying to draw a dashed line with CGContextSetLineDash.
Here's my code:
float dashPhase = 0.0;
float dashLengths[] = {30, 30};
CGContextSetLineDash(context, dashPhase, dashLengths, 20.0);
self.previousPoint2 =…

James Anderson
- 556
- 3
- 16
- 41
7
votes
1 answer
Filling a shape with a gradient in CGContext
I want to fill a polygon shape that I have drawn via Core Graphics with a linear CGGradient. The CGContextDrawLinearGradient function draws a gradient from one point to another but it fills the entire view. How can I display the gradient only…

titaniumdecoy
- 18,900
- 17
- 96
- 133
6
votes
1 answer
Changing the background colour of a CGContext
i'm really new to dealing with CGContexts and i'm just trying to get my head around things by following a simple touch paint & sketch tutorial (http://blog.effectiveui.com/?p=8105)
I have hit a brick wall when it's come to changing the background…

DaveDee
- 63
- 1
- 4
6
votes
1 answer
How could I get CGContextRef from UIImage?
CGContextRef context = ??; // get from UIImage *oldImage
CGContextSaveGState(context);
CGRect drawRect = CGRectMake(0, 0, 320, 480);
CGContextConcatCTM(context, transform);
UIImage *newImage = [[UIImage alloc] init];
…

Kordan Ou
- 1,502
- 3
- 15
- 25
6
votes
0 answers
Adding text in a bitmap graphic context (on macOS) with Swift
My project is
to paste some image crops on a bitmap graphic context
to add some text
to save the bitmap as a JPEG image
I have no problem for 1) and 3) but I can’t find a way for adding text to the bitmap graphic context. I spent many hours…

Jean-Pierre
- 71
- 1