7 Best Astrology Apps for Accurate Horoscopes
Millions of people across the globe turn to astrology for guidance in love, career, health, and personal growth. A survey by Pew Research Center found that 29% of Americans believe […]
You can draw anything by using GestureOverlayView class in android.
Required:-
1. Implement the OnGesturePerformedListener interface
2. Override onGesturePerformed method.
In your xml layout file, add the following code.
Here, we use android.gesture.GestureOverlayView to take input from user and an image view to display output.
<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”
xmlns:tools=”http://schemas.android.com/tools”
android:layout_width=”match_parent”
android:layout_height=”match_parent” >
<android.gesture.GestureOverlayView
android:id=”@+id/gestureOverlayView1″
android:layout_width=”match_parent”
android:layout_height=”match_parent” />
<ImageView
android:id=”@+id/imageView1″
android:layout_width=”match_parent”
android:layout_height=”match_parent”
/>
</RelativeLayout>
In your MainActivity.java class write the following code:-
public class MainActivity extends Activity implements OnGesturePerformedListener{
GestureOverlayViewgestureOverlayView;
private Bitmap bitmap;
private ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Instantiate the object of image view and gesture overlay //view.
imageView=(ImageView) findViewById(R.id.imageView1);
gestureOverlayView = (GestureOverlayView) findViewById(R.id.gestureOverlayView1);
//add listener to the gesture overlay view
gestureOverlayView.addOnGesturePerformedListener(this);
//Create object of Display class to get width and height of device to create a bitmap image of screen size.
Display display= getWindowManager().getDefaultDisplay();
bitmap=Bitmap.createBitmap(display.getWidth(), display.getHeight(), Bitmap.Config.ARGB_8888);
}
//This method will be automatically called by system when //gesture is made by user.
@Override
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
//Create object of canvas and paint class for drawing.
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setColor(Color.BLUE);
// gesture.getStrokes() method will return an array list of Gesture Strokes.
ArrayList<GestureStroke> gestureStrokes = gesture.getStrokes();
for (GestureStroke ges : gestureStrokes) {
//canvas.drawLines method draws the lines on bitmap image by using given points and paint object.
canvas.drawLines( ges.points, paint);
}
//finally display the image using setImageBitmap method in image view as shown below.
imageView.setImageBitmap(bitmap);
}
}
You may also like:
Playing video from the server, application bundle and you tube embed code in iOS Applications
Feb 20th, 2025
Millions of people across the globe turn to astrology for guidance in love, career, health, and personal growth. A survey by Pew Research Center found that 29% of Americans believe […]
Feb 11th, 2025
Remember when your parents warned you never to get into a car with a stranger? Fast forward to today, and getting into a stranger’s car has become a global business […]
Feb 6th, 2025
In today’s digital age, convenience is king, and online gift delivery services are thriving. With the global online gift market expected to grow significantly, now is the perfect time to […]