iOS - Find white pixels/area enclosed by a black curve and create path - ios

Using Swift methods touchBegan, touchMoved and touchEnded I save the touch points and than I draw a line using UIGraphicsGetCurrentContext() with methods beginPath(), move(to: Point), addLine(to: Point) and strokePath().
This line is repeated on 4 quadrants plus their negative values, therefore 8 lines are drawn.
Here is an example:
Example image
I save this drawing as an Image when the user taps the tick (Done green button at top-right) for later manipulations.
I wonder if it's possible to create e closed path/shape with white pixels enclosed by the black lines. I want to fill the white area with custom color when the user touches inside it.
The shape is created by user input and I have no idea how it would look like.
Would be thankful to whoever finds the time to give it's contribute.
Thank you

Maybe what you want is the "Flood Fill" algorithm, please see the article.

Related

How to draw multiple circles within circle like target and get touch event of particular circle?

I want to draw target view like this-
And get touch event of a particular circle.
e.g If user touch between circle 7 then fill black color of circles up to circles 7.
Currently I have two ways to implement this functionality:
1) Take 10 UIImageView and put on each other and touch of an image view change the colors of image view's according to conditions.
2) Take UIView and draw 20 color gradient (10 for black border line and 10 for white spaces) and save frame of each gradient. After that get user's touch area then change color according to that.
I am looking for a better solution.
why not have a single image, and calculate the radius based on the touch point - all you need to know is the centre position.
Instead of radius, what you really need is an index from 0 to 11 for your bands - if they are equal thickness, you can do that in a single calculation - take the integer part of (11 * radius / radiusFull)
If the bulls-eye is a different size, you may need to add some more code.
Either way, you should be able to do it all with a single image - generated on the fly, or simply loaded - and a bit of simple maths.

How to create popup and intersecting line passing through center of plot symbol in core plot?

How can i create popup and intersecting line passing through center of plot symbol in core plot similar to LineChartView Link:
Screen Shot. Thanks
The Mac CPTTestApp example app includes a "Selection Demo" that draws a cross through the selected point. It is trivial to modify that code to draw only the vertical line. Many of the example apps display a label over the selected point. It's easy to add a border and fill to the text layer that displays the selected value.

iOS draw line with both arrow with start-end point while finger touch end and rotate from start or end point

I need help making a drawing demo.
When the user draws a line using their finger,
the line has directional arrows on both ends.
When their finger releases, it draws the line with
"?" (question-mark) in center of the line.
Then, when user taps on the "?", it will show a new view and the user can enter a
value, and the value is in that line.
And we can add multiple lines on capture-image and also we can delete
selected line.
I don't understand how can I start developing these features so
please give me an idea or any link, or suggestion to start develop this
feature.
You should use a UITapGestureRecognizer and a UIBezierPath. Have it so that person taps at one point and then taps at a second point, then make a UIBezierPath between the two points. To get the question mark in the middle you could make it so that the line goes from the first point to (half the distance between point 1 and point 2 - 20pt). And then do the same with the other half of the line (so that you now have a space in the middle of the line.
You can take advantage of the Core Graphics Framework to draw shapes in iOS. This allows you to draw lines, circles, arrows, rectangles etc. Here is some example code to draw a line between 2 points (taken from: How do I draw a line on the iPhone?):
CGContextRef c = UIGraphicsGetCurrentContext();
CGFloat red[4] = {1.0f, 0.0f, 0.0f, 1.0f};
CGContextSetStrokeColor(c, red);
CGContextBeginPath(c);
CGContextMoveToPoint(c, 5.0f, 5.0f);
CGContextAddLineToPoint(c, 50.0f, 50.0f);
CGContextStrokePath(c);
First define a subclass of UIView to create a space to draw in. Then use a UITapGestureRecognizer to detect taps. As #WyattMufson suggested in his answer, I would get the user to tap once to get the start point of the line and then tap again to get the end point. This is done to ensure that only straight lines can be drawn.
Once you have the start point and end point you can calculate the mid point and connect the two points with a '?' character in between. Then save these line coordinates (start, mid and end points) in some sort of data structure to keep track of all the lines that have been drawn.
When the user taps on a specific line, you can use the saved line coordinates information to detect whether the tap occurred on a line or not (you will have to perform some calculations to do this). If so, display a popover that accepts user input. Once the user inputs a value, close the popover and replace the '?' with the new value.
For line deletion, you could use the UILongPressGestureRecognizer. The user would tap and hold on a drawn line, which would bring up a popover to confirm whether the user wants to proceed with deletion or not. If they do, access the saved line coordinates to detect whether the hold occurred on a line or not. If so, erase that line.
Here are some references to get you started:
How make a simple drawing app with UIKit
How do I draw a line on the iPhone?
Check is a point (x,y) is between two points drawn on a straight line
How to get UITouch location from UIGestureRecognizer

Rounded textBox

Is ShapeRenderer class has the ability to do this,I would like to create boundaries for a custom object (such as a rectangle with rounded corners) and then fill it.And after that some text on that filled rounded box.
shapeRenderer.begin(ShapeType.Filled);
shapeRenderer.setColor(Color.RED);
//shapeRenderer.line(...);
shapeRenderer.curve(x1, y1, cx1, cy1, cx2, cy2, x2, y2, segments);
shapeRenderer.line(...);
shapeRenderer.curve(...);
shapeRenderer.line(...);
shapeRenderer.curve(...);
shapeRenderer.line(...);
shapeRenderer.curve(...);
shapeRenderer.setColor(Color.BLACK);
shapeRenderer.fill();
shapeRenderer.end();
Any suggestion to do it in libgdx.
As Lestat said, you can use Scene2d.
Whether you are using Scene2d or not, a NinePatch would probably be suitable if you want to draw a rounded rectangle that scales well (check this link).
If you want to be able to set the color of your image/control, you can use NinePatch.setColor().
Here are two example scenarios regarding colors:
You will always have a black stroke/outline, and an arbitrary fill. In this case make the original image have black stroke/outline and white interior. When you 'tint' the image using NinePatch.setColor(), the stroke/outline will be unaffected and will remain black, while the interior (fill) will be the same as the color provide to the mentioned method.
You have arbitrary fill and arbitrary stroke. In this case you need 2 separate original images. First one would contain the 'fill' and would be completely white. Second one would contain the 'stroke' in white color and would be transparent inside. When drawing you would draw first the fill with its tint and then the stroke with its tint and that's all.
If for some reason you needed different corner curve radii, you would probably need separate images (or image pairs) for each radius to get the best result.

WP7.5 Mango Tile BackContent alignment

Is it possible to center-align the BackContent of a tile?
For example:
54"
2-2
I want the above two lines aligned centered on the back side of a tile. Is this possible?
Sample: http://www.silverlightshow.net/Storage/Users/AndreaBoschin/__Capture.png
You have to draw the text manually onto your BackBackgroundImage as you cannot adjust the placement of the BackContent.
It is not possible to update your Tile with animations or sound. The
placement of the Tile properties is not customizable.
MSDN Source
Edit: Have a look at this question, there is example code showing how to do it.
Draw a image, where it's aligned, and use that as a back property. I've written a guide about it.
(For the front tile, but the backtile is no different).

Resources