Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Android
I am new to android application.I want to know how to draw over the image in android application?
Posted 26-Sep-11 21:57pm
Comments
thhangaraj at 27-Sep-11 4:04am
   
I want to know draw line over the image
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

try this Code:
 
 
package com.cal;
 
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.View;
 
import java.util.ArrayList;
import java.util.List;
 
public class CircleCanvas extends View
{
    public List<circleinfo> mCircleInfos = new ArrayList<circlecanvas.circleinfo>();
 
    public static class CircleInfo
    {
        private float x;
        private float y;
        private float radius;
        private int color;
 
        public float getX()
        {
            return x;
        }
        public void setX(float x)
        {
            this.x = x;
        }
        public float getY()
        {
            return y;
        }
        public void setY(float y)
        {
            this.y = y;
        }
        public float getRadius()
        {
            return radius;
        }
        public void setRadius(float radius)
        {
            this.radius = radius;
        }
        public int getColor()
        {
            return color;
        }
        public void setColor(int color)
        {
            this.color = color;
        }
    }
    public CircleCanvas(Context context)
    {
        super(context);
    }
    @Override
    protected void onDraw(Canvas canvas)
    {
        super.onDraw(canvas);
        for (CircleInfo circleInfo : mCircleInfos)
        {
            Paint paint = new Paint();
            paint.setColor(circleInfo.getColor());
            canvas.drawCircle(circleInfo.getX(), circleInfo.getY(), circleInfo.getRadius(), paint);
        }
    }
}
</circlecanvas.circleinfo></circleinfo>
 
and use it in the Activity ,eg in btn clicked:
just like this:
listener3 = new OnClickListener() {
            public void onClick(View v) {
                 Random random = new Random();
                    float randomX =( 100 + random.nextInt(100));        //
                    float randomY =( 100 + random.nextInt(100));         //
                    float randomRadius =( 20 + random.nextInt(40));     //
                    int randomColor = 0;
                    //
                    if(random.nextInt(100) > 50)
                    {
                        randomColor = Color.BLUE;
                        //randomColor = Color.RED;
                    }
                    //
                    else
                    {
                        if(random.nextInt(100) > 50)
                            randomColor = Color.RED;
                        else
                            randomColor = Color.GREEN;
                    }
                    CircleInfo circleInfo = new CircleInfo();
                    circleInfo.setX(randomX);
                    circleInfo.setY(randomY);
                    circleInfo.setRadius(randomRadius);
                    circleInfo.setColor(randomColor);
                    mCircleCanvas.mCircleInfos.add(circleInfo);        //
                    mCircleCanvas.invalidate();                    //

            }
        };
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 17 Mar 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100