java - RotateAnimation rotates two times instead of just once -


i trying implement feature user can rotate picture. thought of using rotateanimation so:

rotateright.setonclicklistener(new onclicklistener(){      @override     public void onclick(view v) {      //create new bitmap rotated 90 deg     matrix mat = new matrix();     mat.postrotate(90);//90 degree rotation right     bitmap bmaprotate = bitmap.createbitmap(bmp, 0, 0, bmp.getwidth(), bmp.getheight(), mat, true);//create new bitmap rotated angle     bmp = bmaprotate; //save rotated bitmap bitmap uploaded      rotateanimation rotateanim = new rotateanimation(0f, 90f, animation.relative_to_self, 0.5f, animation.relative_to_self, 0.5f);     rotateanim.setduration((long)100);     rotateanim.setrepeatcount(0);     rotateanim.setfillafter(true);//maintains rotation     previewimage.startanimation(rotateanim);      previewimage.setimagebitmap(bmp);//set bitmap rotated 1 (if don't this, animation start initial position       }  }); 

however, when picture rotates 2 times first time button clicked. every time after picture rotates properly. thing note picture saved in bmp has right rotation 90deg off imageview (previewimage) showing

let me know if can give guys further details.

i'm sorry, don't know looking for, if want rotate image, suggest use bufferedimage, affinetransform rotate it.

first call resource @ beggining of program (if have image call).

bufferedimage image = null; try {     image = imageio.read( myclass.class.getresourceasstream( "scr/someimage.png" ) ); } catch ( java.io.ioexception ioexception ) {      joptionpane.showmessagedialog( null, "it not possible load dot cursor." );     system.exit( 0 ); } 

after that, if wish rotate, do:

bufferedimage rotatedimage = new bufferedimage( image.getwidth(), image.getheight(), bufferedimage.type_int_argb );  affinetransform rotate = affinetransform.getrotateinstance( math.pi/2 ); //must in radian. math.pi/2 = 90ยบ bufferedimageop buffiop = new affinetransformop( rotate, null );  graphics2d g2 = rotatedimage.creategraphics(); g2.drawimage( image, buffiop, 0, 0 ); g2.dispose(); 

i don't know if usefull you, hope helped in way.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -