1

Im loading images stored from my apps directory using UIL into an imageView.what i want to do is to draw a small circle over the image on the screen based on the users touch. so i decided to use a surface view. i can draw the circle based on the onTouch Event but the problem im facing is that the whole screen has a white background.i want the circle to be drawn over the imageview.

public class SingleViewActivity extends Activity {
int position;
String[] imageUrls;
ImageView imageView;
ImageLoader imageloader;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.single_view);
    File Path = getExternalFilesDir(null);
    Constants cons = new Constants();
    imageUrls = cons.getImagePath(Path.toString());
    // Get intent data
    Intent i = getIntent();

    // Selected image id
    position = i.getExtras().getInt("position", -1);
    imageView = (ImageView) findViewById(R.id.SingleView);
    imageloader = ImageLoader.getInstance();
    imageloader.displayImage("file://" + imageUrls[position], imageView);
    setContentView(new DrawingView(this));

}

class DrawingView extends SurfaceView {

    private final SurfaceHolder surfaceHolder;
    private final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

    public DrawingView(Context context) {
        super(context);
        setZOrderOnTop(true);
        surfaceHolder = getHolder();
        surfaceHolder.setFormat(PixelFormat.TRANSLUCENT);
        paint.setColor(Color.RED);
        paint.setStyle(android.graphics.Paint.Style.FILL);

    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            if (surfaceHolder.getSurface().isValid()) {
                Canvas canvas = surfaceHolder.lockCanvas();
                canvas.drawCircle(event.getX(), event.getY(), 50, paint);
                surfaceHolder.unlockCanvasAndPost(canvas);
            }
        }
        return false;
    }
}

}
Clinton Dsouza
  • 330
  • 4
  • 20

0 Answers0