Questions tagged [cgcontext]

The CGContextRef opaque type represents a Quartz 2D drawing destination.

977 questions
114
votes
13 answers

Changing UIImage color

I'm trying to change color of UIImage. My code: -(UIImage *)coloredImage:(UIImage *)firstImage withColor:(UIColor *)color { UIGraphicsBeginImageContext(firstImage.size); CGContextRef context = UIGraphicsGetCurrentContext(); [color…
RomanHouse
  • 2,552
  • 3
  • 23
  • 44
57
votes
8 answers

Setting A CGContext Transparent Background

I am still struggling with drawing a line with CGContext. I have actually go to line to draw, but now I need the background of the Rect to be transparent so the existing background shows thru. Here's my test code: (void)drawRect:(CGRect)rect { …
Jim B
  • 2,267
  • 6
  • 24
  • 26
55
votes
4 answers

UISearchBar CGContext ERROR

I have a UISearchBar inside a view, whenever I tap on it, after the keyboard comes up - after -(BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar it sends this to the console: : CGContextSetStrokeColorWithColor: invalid context 0x0.…
henTdev
  • 828
  • 2
  • 7
  • 12
54
votes
6 answers

Contex Drawing + Pagination

I am trying to draw contents of scrollview into a PDF context & I am facing problem with pagination. Following Code I have used: - (void)renderTheView:(UIView *)view inPDFContext:(CGContextRef)pdfContext { // Creating frame. CGFloat…
Sam
  • 902
  • 8
  • 16
53
votes
18 answers

Cut transparent hole in UIView

Looking to create a view that has a transparent frame inside of it so that the views behind the view can be seen through this transparent frame, but areas outside of this will not show through. So essentially a window within the view. Hoping to be…
tiltem
  • 4,952
  • 3
  • 23
  • 26
41
votes
8 answers

Draw a simple circle uiimage

I try to make a 20x20 UIImage with a simple blue circle. I try with this function, but the result is a blue circle in a black square. How do I remove the black square around the circle? Function: + (UIImage *)blueCircle { static UIImage…
matti157
  • 1,288
  • 2
  • 13
  • 26
35
votes
5 answers

iOS draw filled Circles

Not a graphics programmer here, so I'm trying to stumble through this. I'm trying to draw 9 filled circles, each a different color, each with a white border. The UIView's frame is CGRectMake (0,0,60,60). See attached image. The problem is I'm…
RegularExpression
  • 3,531
  • 2
  • 25
  • 36
34
votes
8 answers

I am getting unsupported parameter combination CGBitmap error with swift

I am trying to create a CGContext in swift. It compiles but throws an error at runtime. let colorSpace:CGColorSpace = CGColorSpaceCreateDeviceRGB() let context:CGContext = CGBitmapContextCreate(nil, 20, 20, 8, 0, colorSpace,…
loopmasta
  • 1,693
  • 3
  • 14
  • 19
25
votes
2 answers

CGContextSaveGState vs UIGraphicsPushContext

There are two drawRect methods: - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSaveGState(context); // do drawing here CGContextRestoreGState(context); } And -…
Vadym
  • 1,067
  • 1
  • 13
  • 24
24
votes
2 answers

CGBitMapContextCreate Method Causes Compiler Warning Xcode 5 not Xcode 4

I just updated Xcode from version 4.6.2 to 5.0, and after doing a method in my project (created in Xcode 4.6.2) is suddenly giving a compiler warning. I have tried re-opening the project in both the old and new versions of Xcode, and I have…
jac300
  • 5,182
  • 14
  • 54
  • 89
22
votes
1 answer

Iphone How to make context background transparent?

CALayer *sublayer = [CALayer layer]; /*sublayer.backgroundColor = [UIColor blueColor].CGColor; sublayer.shadowOffset = CGSizeMake(0, 3); sublayer.shadowRadius = 5.0; sublayer.shadowColor = [UIColor blackColor].CGColor; sublayer.shadowOpacity =…
MegaManX
  • 8,766
  • 12
  • 51
  • 83
22
votes
2 answers

Xcode 7 Playground error: invalid context 0x0

I am having this error in debug area, even when my playground file is empty: Sep 23 11:03:50 MyPlayground[68315] : CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental…
Fengson
  • 4,751
  • 8
  • 37
  • 62
22
votes
2 answers

Put border around partially transparent Image being drawn on CGContext

I have an image with a yellow vase in the foreground and transparent background: I'm drawing it on a CGContext: CGContextDrawImage(context, CGRectMake(0, 0, 100, 100), myImage.CGImage); I can draw a shadow around it by using the following…
Sanjay Chaudhry
  • 3,181
  • 1
  • 22
  • 31
19
votes
1 answer

drawInRect: losing Quality of Image resolution

I am trying to erase image using following code CGColorRef strokeColor = [UIColor whiteColor].CGColor; UIGraphicsBeginImageContext(imgForeground.frame.size); CGContextRef context = UIGraphicsGetCurrentContext(); [imgForeground.image…
Shashank Kulshrestha
  • 1,556
  • 17
  • 31
18
votes
6 answers

UIGraphicsGetImageFromCurrentImageContext memory leak with previews

I'm trying to create previews images of pages in a PDF but I have some problems with the release of memory. I wrote a simple test algorithm that cycles on the problem, the app crashes near the 40th iteration: NSArray *paths =…
Alessandro
  • 361
  • 1
  • 2
  • 7
1
2 3
65 66