1. Download our Official Android App: Forums for Android!

Apps Rotate ellipse on image when rotate the image in Android

Discussion in 'Android Development' started by shakatreh87, Feb 13, 2014.

  1. shakatreh87

    shakatreh87 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    3
    Joined:
    Jul 3, 2013

    Jul 3, 2013
    3
    0
    5
    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:



    @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];

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

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

    Advertisement

  2. Unforgiven

    Unforgiven OK Google
    Moderator
    Rank:
     #1
    Points:
    4,238
    Posts:
    36,038
    Joined:
    Jun 23, 2010

    Jun 23, 2010
    36,038
    41,667
    4,238
    Male
    Douglas, MA
    I moved this to the Application Development forum to get some better eyes on it.:)
     
  3. DaytonaJohn

    DaytonaJohn Newbie
    Rank:
    None
    Points:
    15
    Posts:
    12
    Joined:
    Dec 27, 2013

    Dec 27, 2013
    12
    0
    15
    Male
    Instead of extracting the elements of the Matrix and doing your own matrix calculations, use the mapPoints() method of the Matrix class (that is what the method is for).
     

Share This Page

Loading...