Rotate ellipse on image when rotate the image in Android

Belal Shakhatrah

New member
Jan 13, 2013
0
0
0
Visit site
I'm having Android code to move, zooming and rotation image. And it working perfect. Now I want to set ellipse on the image and changing it place upon image changes. The ellipse is drawing perfect in moving and zooming cases, but I don't know how to set new points for the ellipse if I rotate the image.

this is the code I'm using:

Code:
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (!isInitialized) {
        int w = getWidth();
        int h = getHeight();
        position.set(w / 2, h / 2);
        isInitialized = true;
    }

    Paint paint = new Paint();

    matrix.reset();
    matrix.postTranslate(-width / 2.0f, -height / 2.0f);
    matrix.postRotate(getDegreesFromRadians(angle));
    matrix.postScale(scale, scale);
    matrix.postTranslate(position.getX(), position.getY());

    canvas.drawBitmap(bitmap, matrix, paint);

    try 
    {
        float x=250;
        float y=200;

        float[] values = new float[9];
        matrix.getValues(values);

        x =values[Matrix.MSCALE_X]*x+values[Matrix.MTRANS_X];
        y =values[Matrix.MSCALE_Y]*y+values[Matrix.MTRANS_Y];

        y+values[Matrix.MTRANS_Y], xC, yC);


        paint.setColor(0xFF007F00);
        canvas.drawCircle(x, y, 15, paint);

    }
    catch(NullPointerException e) {
        // Just being lazy here...
    }
}
 

Trending Posts

Forum statistics

Threads
943,176
Messages
6,917,645
Members
3,158,860
Latest member
smokedog87