旋转图像的机器人 [英] Rotate image in android

查看:116
本文介绍了旋转图像的机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在这两个方面顺时针和反时针旋转图像。 我有尝试,但不能旋转图像两种方式,  所以嘿给我的解决方案我的问题,如果你知道..

I want rotate image in both the ways Clockwise as well as Anti clock wise. I had try but not rotate image both the way, so plz give me solution for my problem if you know..

在此先感谢......... ///

Thanks in Advance.................///

推荐答案

使用以下

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);
}}

这篇关于旋转图像的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆