0

ビットマップを回転させるときに問題が発生しました。私の要件は次のとおりです。

  1. カメラを介して画像をキャプチャし、キャプチャした画像を ImageView に表示します。
  2. 画像をクリック/タッチすると、画像ビューに 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);
    
4

1 に答える 1

2

ボタンをクリックするたびに、変更した画像ではなく、元の画像を参照しているためです。変更した画像の回転または変更を続けたい場合は、それを参照する必要があります。オリジナルではありません。

グローバル変数を作成し、変更されたビットマップをそこに保存するだけです。次に、ボタンが押されたときに、それが null かどうかを確認します。null の場合は、オリジナルを使用します。それ以外の場合は、変更されたものを使用します

于 2012-06-05T18:02:30.493 に答える