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
Post a Comment