ビットマップを回転させるときに問題が発生しました。私の要件は次のとおりです。
- カメラを介して画像をキャプチャし、キャプチャした画像を ImageView に表示します。
画像をクリック/タッチすると、画像ビューに 2 つのボタンが表示されます。1 つのボタンは画像を時計回り (45 度) 方向に回転し、もう 1 つのボタンは画像を反時計回りに回転します。
このプロセスには以下のコードを使用しましたが、残念ながら一度しか機能しません。最初にボタンをクリックすると、45度に対応する画像が回転し、その後ボタンクリックに変化はありません。// オンクリック
public void onClick(View 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);