How can i draw bezier curve in android , can any one suggest some references or existing source code that helps me to understand bezier curve .i want to crop image in my android app using any close path like Bezier Path. i know it is possible using rectangle but i want crop in different shape. like i make one shape using touch and want to crop that image so how it is possible. any suggestion or help. Thanks in advance.
You best bet would be to use the quadTo and cubicTo and other utility methods available in the Path class. All you have to do is determine the control points.
I have written a simple tutorial on how to use Path and PathMeasure to draw lines, curves, etc., You may find it here:
http://c05mic.wordpress.com/2012/03/23/animating-a-bitmap-using-path-and-pathmeasure-android/
Related
Hi,
I'm trying to understand how to make custom view (with green background) on Android like represented on attached image. Please suggest, should I use Path for this or something else?
A good starting point would be http://tips.androidhive.info/2013/09/android-layout-rounded-corner-border/ . Then you can play with the attribute values to get the desired background. Hope this helps.
You have two good options for accomplishing this.
Bitmap
Create the desired image in Photoshop, Gimp or something similar. Export it as a png file then import it as a bitmap resource into your Android application.
This is by far the simpler and faster of the two methods, but here are two significant problems. First, you should supply bitmaps for each screen density bucket. Second, each bitmap resource you add increases the install size of your app. This can get out of hand quickly.
Path
As you mentioned in your question, you can draw the desired shape directly onto a canvas using a Path. More specifically, you'll use the cubicTo() method to create bezier curves.
I recommend using your image editor's "path" tool to learn how the control points affect the curve. Once you've drawn the shape in the image editor, write down the coordinates for every point on your path as well as the corresponding control points. Then do a little math to convert the points to ratios of the image's overall width and height.
You can implement the shape in your app as a View or as a Drawable. In either case, you'll be drawing to a Canvas. The important step will be to set up the path by multiplying the ratios with the size of your drawing area. After you draw the fancy edge, be sure to draw the straight edges via lineTo() and to close the shape with close().
I'm searching for a way of filling the Area under a cubic Bezier curve in Android. To be specific I'm trying to draw a Figure like in the Picture below in a Custom View. My idea is to draw a circle and two mirrored cubic Bezier curves and fill the area beneath them. Is there an Android built in way to archive this, or do I have to find another solution? If so can you help me find an alternative solution?
The shape I would like to draw:
What you need here is Path. More info here:http://developer.android.com/reference/android/graphics/Path.html
In your case, you need to create a Path
Move that to a point that you want via path.moveTo()
Add the first bezier curve via path.cubicTo()
Add the circle to the path via path.addCircle()
Add the second bezier curve via path.cubicTo()
Finally, close the path via path.close()
As for the fill of the path. Normally, the path is filled inside. If you are looking for something else, I suggest you play around with path.setFillType().
I need to move the image in the canvas. The image should not follow a linear or circle or elliptical path. I know this can be achieved by using the COS and SIN functions. But here I need to get the image traversed in a 4 different path like I have shown in the below snapshot. Please help me if there is anyway to achieve this. It should be fine even If I get any idea to achieve this .
snapshot:
I'd try the android animation package first - you should be able to define a few points and get this to smooth the path between the points.
See here: http://developer.android.com/guide/topics/graphics/view-animation.html
I'm trying to create a jigsaw puzzle app for Android. I am fairly far into the coding, and I am kind of stuck with one issue.
I need a way to change a Bitmap into a bunch of puzzle pieces. My current code simply cuts the image into rectangles, and it works pretty well, but now I need a way to create more complex piece shapes.
I had a couple of ideas:
Use a separate bitmap file that contains only black and white pixels, and use that to cut up the picture. I thought this was a pretty good plan, until I went to code it. I really had no idea how to do it.
Use a Path object to create the border. This would probably work, except I'm not sure how to keep track of the sides so that the pieces connect with each other.
Any ideas? I'm open to any suggestions.
You can use Path and/or Region to set a clip for your Canvas when drawing a Bitmap.
Take a look at this example. Here are some ways of clipping your drawing to any shape.
You could try making squares or rectangles fitted inside complex figures that can still be pieced toguether, when there's a match, the full rectangle covers the space. Imagine it like a 9 patch, when two sides match, you show the border rectangle.
This is not a explicit solution but I wonder if it would be possible to use bezier curves or paths to create lines along x and y , in conjunction with a parameter(fed with random value) to control the amount of deviation from a straight line and how much in a given distance ie; pixels/ per inch - this would be to create tongues on the pieces. Then use Region to extract the resulting shape at a given side of an intersection. Have the shape object get its center xy coordinate at instantiation and make it so that piece cannot be set if its current coordinate does not match the one it had when it was created.
Can somebody suggest me svg library for android? I have a list of objects with coordinates and I need to draw them like circles on a svg picture and on click a new activity shall be opened. It is importanrt that I can implement zoom in/out on that map.
You can extend a view and override the onDraw method which gives you the canvas.
Using the canvas you can draw circles.
One svg library that works on mobile devices is d3.
It can do everything you described. (Take a look at this code example with zoomable circles).
Here you can find a video tutorial that explains how to use d3 for mobile devices.