gpt4 book ai didi

android - 在android中旋转图像

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:26:12 24 4
gpt4 key购买 nike

我想以顺时针和逆时针两种方式旋转图像。我尝试过但没有同时旋转图像, 所以如果你知道,请给我解决我的问题的方法..

提前致谢................................///

最佳答案

使用下面的代码

public class Rotateimage extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gallery);
// or just load a resource from the res/drawable directory:
Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.flo);

// find the width and height of the screen:
Display d = getWindowManager().getDefaultDisplay();
int x = d.getWidth();
int y = d.getHeight();

// get a reference to the ImageView component that will display the image:
ImageView img1 = (ImageView)findViewById(R.id.imageView1);

// scale it to fit the screen, x and y swapped because my image is wider than it is tall
Bitmap scaledBitmap = Bitmap.createScaledBitmap(myBitmap, y, x, true);

// create a matrix object
Matrix matrix = new Matrix();

matrix.postRotate(45, 90, 180);

// create a new bitmap from the original using the matrix to transform the result
Bitmap rotatedBitmap = Bitmap.createBitmap(scaledBitmap , 0, 0, scaledBitmap .getWidth(), scaledBitmap .getHeight(), matrix, true);
// display the rotated bitmap
img1.setImageBitmap(rotatedBitmap);
}}

关于android - 在android中旋转图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5389613/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com