Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:图像旋转不希望调整大小_Android_Bitmap_Rotation - Fatal编程技术网

Android:图像旋转不希望调整大小

Android:图像旋转不希望调整大小,android,bitmap,rotation,Android,Bitmap,Rotation,我有一个旋转图像视图的代码,很好。 问题是图像的大小在旋转过程中会发生变化,我希望不会发生这种情况 图像的xml代码 <ImageView android:id="@+id/imgBallesta" android:layout_width="100dp" android:layout_height="100dp" android:layout_alignParentLeft="true" android:la

我有一个旋转图像视图的代码,很好。 问题是图像的大小在旋转过程中会发生变化,我希望不会发生这种情况

图像的xml代码

<ImageView
        android:id="@+id/imgBallesta"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:src="@drawable/imgballesta"
        android:contentDescription="@string/imageString"
         />
还有旋转图像的代码,这个代码是内联的和onTouchEvent的

Matrix mat = new Matrix();
matrix.postRotate((float) (angle*180/Math.PI), image.getWidth(),image.getHeight());
Bitmap bMapRotate = Bitmap.createBitmap(bMap, 0, 0, bMap.getWidth(), bMap.getHeight(), matrix, true);
image.setImageBitmap(bMapRotate);

感谢您的帮助和阅读我的问题

请尝试我的旋转图片方法:

public static Bitmap rotate(Bitmap src, float degree) {
    // create new matrix
    Matrix matrix = new Matrix();
    // setup rotation degree
    matrix.postRotate(degree);

    // return new bitmap rotated using matrix
    return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
}

祝你好运

我找到了解决我问题的可行办法。首先,我修改图像的大小和高度,并为所有可绘制文件夹创建相应的图像。 然后我使用下一个代码为图像设置动画

Matrix matrix=new Matrix();
img.setScaleType(ScaleType.MATRIX);   //required
matrix.postRotate((float) (a*180/Math.PI) , img.getWidth()/2, img.getHeight()/2);
img.setImageMatrix(matrix);

感谢您的回答并阅读此问题。

无任何更改,继续修改图像大小,感谢您的回答。您确定解决方案,我也实施了您的解决方案,但当旋转发生时,我的图像正在调整大小。我记不清了,因为这是一个旧项目。但如果我将其标记为已回答,我认为在编写de代码时它是有效的。
Matrix matrix=new Matrix();
img.setScaleType(ScaleType.MATRIX);   //required
matrix.postRotate((float) (a*180/Math.PI) , img.getWidth()/2, img.getHeight()/2);
img.setImageMatrix(matrix);