旋转位图时出现问题。我的要求如下,如何在Android中点击按钮时旋转位图?
- 通过相机捕获图像并在ImageView中显示捕获图像。
当我点击/触摸图像时,在图像视图上显示两个按钮。一个按钮用于将图像相对于顺时针(45度)方向旋转,另一个按钮用于将图像相对于逆时针方向旋转。
我用下面的代码这个过程中,不幸的是它只能一次一次,当我在第一时间t单击该按钮后,有在按一下按钮没有任何变化都会相应旋转45度的图像。 //的onclick
公共无效的onClick(视图v){
switch (v.getId()) { case R.id.right_image_rotate: try { System.gc(); Runtime.getRuntime().gc(); unbindDrawables(findViewById(R.id.image_viewer)); imageRotate(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } break; case R.id.left_image_rotate: try { System.gc(); Runtime.getRuntime().gc(); unbindDrawables(findViewById(R.id.image_viewer)); imageRotate(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } break; case R.id.image_viewer: rotateLayout.setVisibility(View.VISIBLE); imageLeft_rotate.setVisibility(View.VISIBLE); imageRight_rotate.setVisibility(View.VISIBLE); break; default: break; } } Bitmap bitmapOrg = BitmapFactory.decodeFile(saved_image_file .getAbsolutePath()); int width = bitmapOrg.getWidth(); int height = bitmapOrg.getHeight(); int newWidth = 200; int newHeight = 200; // calculate the scale - in this case = 0.4f float scaleWidth = ((float) newWidth)/width; float scaleHeight = ((float) newHeight)/height; Matrix matrix = new Matrix(); matrix.postScale(scaleWidth, scaleHeight); matrix.postRotate(45); Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width, height, matrix, true); srcBitmap.setScaleType(ScaleType.CENTER); srcBitmap.setImageBitmap(resizedBitmap);
我们需要更多的代码。你在使用onClickListener吗? matrix.portRotate(deg)也应该在45度下正常工作。 – bhekman
看到这个答案http://stackoverflow.com/a/10332901/1289716 和http://stackoverflow.com/a/10042149/1289716 – MAC
@BradHekman:我累了,但它只有一次。当我点燃拳头时,它会旋转,然后我点击第二次意味着它不会旋转。 – Aerrow