CGPath masked off CGPoints - iphone

I'm trying to build this:
Where the white background is in fact transparent. I know how to clip a CGPath to a set region, but this seems to be to other way around, since I need to substract regions from a filled CGPath.
I guess the right way to go would be to substract the whole outer-circles from the CGPath and then to draw smaller circles at my CGPoints, but I'm not sure how to execute the former. Can anyone point me in the right direction?

That's what I would do :
1) Draw your general line
2) CGContextSetBlendMode(context, kCGBlendModeClear) to "clear the context" when you draw.
3) Draw you bigger circles
4) CGContextSetBlendMode(context, kCGBlendModeNormal) to return to normal drawing
5) Draw your little circles.

You could instead start a transparency layer, draw the lines, then draw the larger transparent circles using the clear color, then draw the smaller black circles. Then when you finish the transparency layer, it will composite exactly what you want back onto the context.

Related

iOS Quartz 2D Graphics Filled Irregular Shapes Blurry

I'm drawing irregular shapes using Core Graphics on a retina display. I do this by creating a UIBezierPath with 5 to 10 random points. In drawRect I stroke the path and fill it using solid red colour.
My problem is that diagonal lines in my drawing doesn't appear to be sharp.
I have tried anti aliasing but if anything this makes it appear worse. I have experimented with different line widths, not stroking, not filling, but I can not seem to get a really sharp diagonal line.
For comparison I created a similar shape in Photoshop (using similar size) and saved that as PNG. If I display that PNG on iOS it looks much sharper.
What can I do to make my shape that I create in code look sharp?
Make sure your CGPoint's are rounded to the nearest integer value.

Quartz 2D -Drawing a point

I know that drawing a point by using drawing a line method in Quartz 2D is
CGContextMoveToPoint(context,x,y-0.5f);
CGContextAddLineToPoint(context,x,y+0.5f);
Is there any other possible way to draw a point using Quartz?
I meant, some direct way of doing so?
CGContextFillRect(context, CGRectMake(x,y,1,1));
if you want it to look like a circular point try this:
CGContextStrokeEllipseInRect(context, CGRectMake(x, y, 4, 4));
it will draw for you you a an ellipse inside a rectangle (above case is apparently a square). i prefer you to choose a square as it will look like a real circle and not oval one. however, this circle will be empty from the inside, you can fill it by a stroke. (but it looks cool like a donut!) :)

Inner Shadow Effect for line drawn to screen?

I've made an iOS program that allows the user to draw a line on the screen with their finger. I used the touchesBegan, touchesMoved, and touchesEnded methods, along with creating a CGContext and drawing my line that way. I want the line to look as though it is beveled into the screen, almost as if it was carved. How would this be possible?
You can achieve a simple bevel by stroking your lines three times:
first, with a color brighter than the background at points p(x-1, y-1) relative to the actual line
then, your line color at the actual line position, points p(x, y)
then, brighter than the line color, but darker than the background at p(x+1, y+1)
You can think of this as a light shining onto your lines from above and to the left, making the lower coordinates brighter, passing over the bevel and having a little shadow cast on the higher coordinates.
Once you get the hang of thinking through the pseudo-3D geometry this way, you can create prettier bevels, including details inside the line. Those will take more strokes.

clear part of UIImage

I've been doing some research on online for a project I'm doing but so far haven't been able to quite get it working. I want to be able to slide my finger over a UIImage and delete part of it, kind of like an eraser. I'm able to draw lines on the screen but can't figure out how to do this. Any help would be greatly appreciated.
Can you mask the image and when you draw on it, it adds the lines to the mask (in white, rest of mask is black) and then it should make those spots transparent
http://iosdevelopertips.com/cocoa/how-to-mask-an-image.html
There are two parts to this problem-
a) Determining the curve along which the finger was moved
b) Drawing the curve (which is really a combination of short lines) with the white color
For part (a), have a look at UIPanGestureRecognizer. Using the touchesBegan: & touchesMoved methods, you will be notified every time the finger moves even the smallest distance, and the source and destination co-ordinates, say (x1, y1) & (x2, y2).
Part (b), As you know how to draw a line, now you need to draw a line from the source to the destination with the line's width (thickness) equal to the finger's. For that you can set the line's width using CGContextSetLineWidth.

CoreGraphics rounded corner thickness

Whenever I stroke a path with rounded corners on iPhone, the rounded corners are thicker than the rest of the stroked path. See here for what I mean:
rounded corner thickness http://img181.imageshack.us/img181/6372/screenshot20100320at123.png
Not sure why this happens, any ideas?
I agree with Peter Hosey's analysis that the outer half of your lines is getting clipped off, but my recommendation would be to move all the coordinates .5 pixels inward instead. This way your straight lines will be crisper (not antialiased across 2 screen pixels) as well.
I suspect that you're drawing within a rectangular clipping path; the corners fall completely within the rectangle, but the sides get cut in half: half inside the clipping path and so drawn, half outside and so clipped out.
Try adding the path to the clipping path before stroking it.
To do this, you will need to add the CGPath to the context's current path twice:
Add CGPath to current path.
Add current path to clipping path (thereby emptying current path).
Add CGPath to current path.
Stroke current path.
It just looks thicker. If you zoom in on it you will see what looks like a couple extra pixels of black is actually some pixels of gray caused by antialiasing.
Try turning off antialiasing to see if the result looks better.
Edit: Also the bottom right corner seems to have a drop shadow effect.