I am trying to draw a line two pixels wide. How can I do this?
There is no method to set the width of your line. You do have two options though:
1) If your line is horizontal/vertical, then you can use fillRect to draw your lines.
2) You can draw multiple lines offset by a pixel in the x or y direction to make the appearance of a thicker line.
They may not be ideal, but they get the job done.
There is no methods to set the width for a line. But if you want you can draw like below code. I don't think this is correct way. But it will help you.
Graphics c = new Graphics();
c.drawLine(5, 20, width-10, 20);
c.drawLine(5, 21, width-10, 20);
Related
I've been digging through the highchairs api and can't seem to find anything, so who knows if it's possible.
I have a graph that represents data as percentages - min and max are concrete at 0, 100 respectively. Linewidth is set at 2 and I've noticed that if values are at max, 100, the line stroke is cut off in the middle - making the line look awkwardly skinny / cramped at the top of the graph.
Is there any property to add to yAxis, series or other that forces the full line stroke to draw?
It's series.clip - so close.
set to false to disable clipping
https://api.highcharts.com/highcharts/plotOptions.series.clip
A user can specify a margin-bottom for a page and I want to be able to draw a horizontal line showing where they have placed it. I have defined margin_bottom in my PDF document (A4 size).
All I need to do is add the specified margin to the X axis and draw a line. However, how can I draw this line?
From my knowledge, I could call something like this
stroke_horizontal_line(0, 0 + margin_bottom)
However, this isn't working and I need it to be the full width of the page.
First of all, I think stroke_horizontal_line works a bit different than you think (if I'm understanding what you are trying to do correctly)
stroke_horizontal_line(x1, x2, at: y) Draws a horizontal line from x1 to x2 at the vertical height of y, where y starts at 0 at the bottom of your document (after bottom margin, not at the bottom of the page).
So, I think you are trying to draw a horizontal line across the whole page, at a specific height which is defined by some variable margin_bottom, to accomplish that with stroke_horizontal_line you can do this:
# You can set a stroke color, if you set it to white it is possible that you just
# forgot to set it back to black.
stroke_color 0, 0, 0, 100
# You can also set the line width
line_width 2
# This would draw a horizontal line across the whole page (not over your side margins)
# at the height of margin_bottom + your document bottom margin (measured from the bottom up)
stroke_horizontal_line(0, bounds.width, at: margin_bottom)
You can also use stroke_horizontal_rule, which just draws a horizontal line at you current cursor position, so you would have to place the cursor on the right spot before using that method.
Easy.
stroke_horizontal_line (y), (y), at: (x)
stroke_horizontal_rule
Should do it.
For better visual appearance want to draw a black border around my text.
Currently i am drawing the same text 5 times.
If i want to draw the text on x = 5, y = 10 i would draw the text one time on the actual position.
Then i would draw the same text in black color with slightly other positions.
x = 4, y = 10
x = 5, y = 9
...
I can only imagine that this is bad performance wise. Or is this the correct way?
I never did it the correct way myself, but it seems here they did it: http://www.codeproject.com/Articles/376597/Outline-Text-With-DirectWrite
I do that too. But I suddenly realise there might be a better way (have not tried it yet): first draw in black with a slightly bigger size, and draw again in white with preferred size. Worth a try? Let me know how that goes.
I want to create bezier path with dynamically changing line's width. I need spending the same amount of color on each part of line. So, longer line should be thinner. And shorter line should be bold. Or, at least, line should change it's width from beginning to the end.
Any ideas how to achieve it?
Thank you.
the only way to achieve this is with multiple UIBezierPaths of different thickness and colour.
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?
CGContextFillRect(context, CGRectMake(x,y,1,1));
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.
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.
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?
You can draw a 1-pixel-length line at the coordinate in question; that should accomplish what you want.
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));
Swift 3 :
UIRectFill(CGRect(x: x, y: y, width: 1, height: 1))
UIRectFill()