私はあなたのコードを試しましたが、回転した後、OutOfMemory例外でクラッシュし、新しいビットマップが作成されるたびに、非常にリソースを消費します。あなたは決して決してすべきではありません!反復でcreateBitMap()を使用します。画像の回転コードに変更を加えましたが、期待どおりに実行されています。
コードは次のとおりです。
private void addListeners() {
this.button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Matrix matrix = new Matrix();
//copying the image matrix(source) to this matrix
matrix.set(imageView.getImageMatrix());
matrix.postRotate(10, imageView.getWidth()/2, imageView.getHeight()/2);
imageView.setImageMatrix(matrix);
//checking the size of the image
Drawable d = imageView.getDrawable();
Bitmap bmp = ((BitmapDrawable)d).getBitmap();
imageInfo(bmp);
}
});
}
また、imageViewのスケールタイプをマトリックスに設定します
<ImageView
android:id="@+id/Image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#336699"
android:scaleType="matrix"
android:padding="2px"
android:src="@drawable/m" />
また、ImageViewから回転したビットマップを取得する場合は、次のようにします。
private Bitmap getBitmapFromView() {
// this is the important code :)
// Without it the view will have a dimension of 0,0 and the bitmap will be null
imageView.setDrawingCacheEnabled(true);
imageView.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
imageView.layout(0, 0, imageView.getMeasuredWidth(), imageView.getMeasuredHeight());
imageView.buildDrawingCache(true);
Bitmap b = Bitmap.createBitmap(imageView.getDrawingCache());
imageView.setDrawingCacheEnabled(false); // clear drawing cache
return b;
}
これがお役に立てば幸いです。