How do I draw a point using Core Graphics?

前端 未结 7 1952
别那么骄傲
别那么骄傲 2020-12-03 07:57

I see APIs in Quartz for drawing lines and circles. But all I want to do is to specify the (x,y) cartesian coordinate to color a pixel a particular value. How do I do that

相关标签:
7条回答
  • 2020-12-03 08:17

    swift 3 :

     UIRectFill(CGRect(x: x, y: y, width: 1, height: 1))
    
    0 讨论(0)
  • 2020-12-03 08:18

    Draw a very small ellipse/circle and fill it!

    CGContextAddEllipseInRect(Context,(CGRectMake (x_dot, y_dot, 3.0, 3.0));
    CGContextDrawPath(Context, kCGPathFill);
    CGContextStrokePath(Context);
    

    I am using this code to create a small dot (3x3 pixels) in a dotted music note.

    0 讨论(0)
  • 2020-12-03 08:22

    I got a point (zero length line) to draw after setting the line-caps to kCGLineCapRound. The default line-cap has no length so can't be drawn.

    The argument that a point has no size is silly. The lines have no width but we can draw those (by using the "line width" from the draw state). A point should draw in exactly the same way, and with different line caps I believe it does.

    Maybe this behavior is new?

    0 讨论(0)
  • 2020-12-03 08:27

    I'm having the same issue - i find the best solution is similar to the last, but at least it doesn't leave something that looks like a "dash"... of course, should ensure x/y are both > 0.

    CGContextFillRect(context, CGRectMake(x - 0.5, y - 0.5, 1.0 , 1.0));

    0 讨论(0)
  • 2020-12-03 08:30

    Quartz is not a pixel-oriented API, and its contexts aren’t necessarily pixel buffers. If you want to draw pixmaps, create a bitmap context with CGBitmapContextCreate(). You provide a buffer, which you can manipulate directly, and can copy to another context by creating a CGImage from the same buffer using CGImageCreate() and drawing that.

    0 讨论(0)
  • 2020-12-03 08:36

    You can draw a 1-pixel-length line at the coordinate in question; that should accomplish what you want.

    0 讨论(0)
提交回复
热议问题