Questions tagged [cgcontextref]
90 questions
1
vote
2 answers
How save CGContextRef as .PNG file?
I create a drawing iOS application in which I would like to create a "Save Image" method.
The drawing takes place inside the touchesMoved: method.
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches…

abg
- 2,002
- 7
- 39
- 63
0
votes
0 answers
CGContext error trying to draw in touchesBegan
- (void)drawRect:(CGRect)rect {
}
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
CGContextRef context = UIGraphicsGetCurrentContext();
UITouch* touch = [touches anyObject];
CGPoint point = [touch…

Serj Semenov
- 267
- 4
- 11
0
votes
0 answers
How can we avoid the extra bezier curve line?
Can we avoid the extra bezier curve line after the last point in Bezier graph? Is there any property for that?
We need just end-end curve graph, no extra curve. Please share the solutions/suggestion. Update: Please check the code below,
-…

Gopik
- 255
- 2
- 17
0
votes
1 answer
CGContextRef draws fuzzy or blurred images
I created new CGContext using:
NSUInteger width = newRect.size.width;
NSUInteger height = newRect.size.height;
NSUInteger bytesPerPixel = 4;
NSUInteger bytesPerRow = bytesPerPixel * width;
NSUInteger…

Artem
- 391
- 3
- 11
0
votes
1 answer
Add image, which drawing with UIBezier or CGContextRef into UIView sublayer
In this code I use CGContextRef to create next picture on my UIView:
CGMutablePathRef arc = CGPathCreateMutable();
CGFloat lineWidth = 16.0;
CGContextRef cont =…

Ivan Trubnikov
- 177
- 1
- 8
0
votes
1 answer
Draw dashed line in iOS
I used CGContext to draw dashed lines in iOS.
My code is as follow.
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
CGFloat dashes[] = {5,5};
CGContextSetLineDash(context,…

batuman
- 7,066
- 26
- 107
- 229
0
votes
2 answers
Different behaviours for different colors in drawRect:
I am puzzled by the way the following code works.
It is expected to produce a black disk surrounded by a colored circle.
It works fine with certain colors (as explained in the comments), but not with some others.
Can anyone explain this misterious…

Michel
- 10,303
- 17
- 82
- 179
0
votes
0 answers
CGContextRef/Objective C to CGContext/Swift confusion
I have a base class, written in objective C which for many reasons, is used to get the CGContext when a sub-class needs to draw in drawRect.
-(CGContextRef)fetchContext
{
CGContextRef context = UIGraphicsGetCurrentContext();
return…

Fittoburst
- 2,215
- 2
- 21
- 33
0
votes
2 answers
create a UIBezierPath of 3 pixels width on retina @2x display
I'm trying to create a line of 3 pixels width on a retina @2x display. The simple idea would be to create a 1.5 width line :
UIGraphicsBeginImageContextWithOptions(CGSizeMake(20, 20), NO, 0.0f);
CGContextRef aRef =…

user3048615
- 21
- 4
0
votes
1 answer
Unable to set fill color in CGContext (CGContextSetFillColorWithColor)
Pardon me, but my knowledge of CGContext is fairly limited.
I am using the code from the accepted answer HERE to draw stars in a UIView. What I want to achieve is show the stars in 2 different colors (like a rating view). The problem is, I cannot…

n00bProgrammer
- 4,261
- 3
- 32
- 60
0
votes
0 answers
iOS generate PDF file with one image on each page
I found this link that describes how to add content to the PDF. So as I understood right the pages will be generated based on input NSString. So the count of pages depends on the length of the string.
I need to implement the same but with the…

Matrosov Oleksandr
- 25,505
- 44
- 151
- 277
0
votes
2 answers
What is a Context in iPhone?
Can any body explain me what is a Context and how can i use it?
There is also Graphics Context (CGContextRef).Is there any relation between Context
and Graphics Context?

raaz
- 12,410
- 22
- 64
- 81
0
votes
1 answer
Strange Error with CGContext
I am getting error
fatal error: Can't unwrap Optional.None
(lldb)
with this code
var context:CGContextRef = UIGraphicsGetCurrentContext()
let radius:CGFloat = 5
CGContextSetRGBStrokeColor(context, 1, 1, 1, 1)
var tempRect:CGRect =…

elito25
- 624
- 1
- 6
- 14
0
votes
1 answer
GPUImage replace colors with colors from textures
Looking at GPUImagePosterizeFilter it seems like an easy adaptation to replace colors with pixels from textures. Say I have an image that is made from 10 greyscale colors. I would like to replace each of the pixel ranges from the 10 colors with…

Joe Andolina
- 648
- 1
- 11
- 23
0
votes
1 answer
ios 7 NSString drawInRect using CoreGraphics
I would like to colour my string and draw it in a rect, my code is
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetTextDrawingMode(context, kCGTextFillStroke);
CGContextSetRGBStrokeColor(context, 210.0/255.0f, 0.0f, 0.0f,…

Xander
- 902
- 2
- 14
- 33