android - Bitmap - Matrix operations (scale, rotate and translate) -


i need matrix operations. i'm trying achieve is:

  • scale down
  • move specific position
  • rotate degree (in center of bitmap)

my code looks this:

            matrix matrix = new matrix();             matrix.prerotate(mship.getrotation(), mship.getx() + mship.getcurrentbitmap().getwidth()/2f, mship.gety()  + mship.getcurrentbitmap().getheight()/2f);             matrix.setscale((1.0f * mship.getwidth() / mship.getcurrentbitmap().getwidth()), (1.0f * mship.getheight() / mship.getcurrentbitmap().getheight()));             matrix.posttranslate(mship.getx(), mship.gety());             mcanvas.drawbitmap(mship.getcurrentbitmap(), matrix, mbasicpaint); 

but rotation has wrong center, , can't figure out how solve - i've looked around on did find similar problems, no solutions this. think might have apply 1 of operations one's values executed in sequence cant figure out how to.

try code:

matrix matrix = new matrix(); matrix.settranslate(-mship.getcurrentbitmap().getwidth()/2f, -mship.getcurrentbitmap().getheight()/2f); matrix.postrotate(mship.getrotation()); matrix.posttranslate(mship.getx(), mship.gety()); matrix.postscale((1.0f * mship.getwidth() / mship.getcurrentbitmap().getwidth()), (1.0f * mship.getheight() / mship.getcurrentbitmap().getheight()), mship.getx(), mship.gety()); 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -