1
            View vvv=mViewFlipper.getCurrentView();             
            RelativeLayout rrr=(RelativeLayout)vvv;
            ImageView img=(ImageView) rrr.getChildAt(0);
            img.setRotation(90); 

            img.setDrawingCacheEnabled(true);
            img.buildDrawingCache();                
            Bitmap bitmap =img.getDrawingCache();             
            img.destroyDrawingCache();
            img.setDrawingCacheEnabled(false);

            int width = bitmap.getWidth();
            int height = bitmap.getHeight();
            Matrix matrix = new Matrix();
            matrix.postRotate(90);
            Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
            BitmapDrawable bmd = new BitmapDrawable(rotatedBitmap); 
            rrr.removeViewAt(0);
            ImageView img_new=new ImageView(ImageSlideShow.this);
            img_new.setImageDrawable(bmd);
            img_new.setScaleType(ScaleType.CENTER);
            rrr.addView(img_new, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

で回転する画像に上記のコードを使用しましたViewFlipper
初めて実行されますが、2回目は返されNullPointerExceptionます...
エラー行:

Bitmap bitmap =Bitmap.createBitmap(img.getDrawingCache());
4

2 に答える 2

0

私はこの問題の解決策を得ました

ImageView img=(ImageView) rrr.getChildAt(0);            
                Matrix matrix = new Matrix(); 
                matrix.set(img.getImageMatrix());
                matrix.postRotate(90, img.getWidth() / 2, img.getHeight() / 2);
                img.setImageMatrix(matrix); 

上記のコードは画像の回転に対して完全に機能し、imageview で android:scaleType="matrix" を設定する必要があります。

于 2014-04-24T04:22:50.153 に答える