旋转 bmp 并将其正面朝上显示

发布于 2024-10-03 04:48:16 字数 553 浏览 6 评论 0原文

我有一个应用程序可以拍摄图片并将图片显示在 Imageview 上。问题是,我只能在横向模式下拍摄照片,以便将 bmp 正面朝上显示 - 如果在纵向模式下拍摄照片,有没有办法可以将其旋转到正面朝上/

谢谢!

这是我用来将图像放置在 img 视图中的代码 -

  private void processCameraImage(Intent intent) {
    setContentView(R.layout.detectlayout);
    ((Button) findViewById(R.id.detect_face)).setOnClickListener(btnClick);

    ImageView imageView = (ImageView) findViewById(R.id.image_view);

    cameraBitmap = (Bitmap) intent.getExtras().get("data");

    imageView.setImageBitmap(cameraBitmap);

有一个检测面部按钮,可以检测是否存在面部。

I have an app that snaps a picture and displays the picture on an Imageview. The problem is, I can only snap a pic in landscape mode in order for the bmp to be displayed right side up - Is there a way I can rotate it to right side up if the pic is taken in portrait mode/

Thanks!

Here is the code I use to place the image in the img view -

  private void processCameraImage(Intent intent) {
    setContentView(R.layout.detectlayout);
    ((Button) findViewById(R.id.detect_face)).setOnClickListener(btnClick);

    ImageView imageView = (ImageView) findViewById(R.id.image_view);

    cameraBitmap = (Bitmap) intent.getExtras().get("data");

    imageView.setImageBitmap(cameraBitmap);

There is a detect faces button that will detect if there are faces present.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

想你只要分分秒秒 2024-10-10 04:48:16

这是旋转 bmp 的方法:

   private Bitmap rotateImage(Bitmap b, float angle)
   {
      //create a new empty bitmap to hold rotated image
       Bitmap returnBitmap = new Bitmap(b.Width, b.Height);
       //make a graphics object from the empty bitmap
       Graphics g = Graphics.FromImage(returnBitmap);
       //move rotation point to center of image
       g.TranslateTransform((float)b.Width/2,(float)b.Height / 2);
       //rotate
       g.RotateTransform(angle);
       //move image back
       g.TranslateTransform(-(float)b.Width/2,-(float)b.Height / 2);
    }

This is how you would rotate a bmp:

   private Bitmap rotateImage(Bitmap b, float angle)
   {
      //create a new empty bitmap to hold rotated image
       Bitmap returnBitmap = new Bitmap(b.Width, b.Height);
       //make a graphics object from the empty bitmap
       Graphics g = Graphics.FromImage(returnBitmap);
       //move rotation point to center of image
       g.TranslateTransform((float)b.Width/2,(float)b.Height / 2);
       //rotate
       g.RotateTransform(angle);
       //move image back
       g.TranslateTransform(-(float)b.Width/2,-(float)b.Height / 2);
    }
浮生未歇 2024-10-10 04:48:16

这是我在活动中使用 onActivityResult() 的代码。返回的意图是选择 image/* 类型的图像。对我来说效果很好!

Uri imageUri = intent.getData();
                String[] orientationColumn = {MediaStore.Images.Media.ORIENTATION};
                Cursor cur = managedQuery(imageUri, orientationColumn, null, null, null);
                int orientation = -1;
                if (cur != null && cur.moveToFirst()) {
                    orientation = cur.getInt(cur.getColumnIndex(orientationColumn[0]));
                }  
                Matrix matrix = new Matrix();
                matrix.postRotate(orientation);

Here is the code I used onActivityResult() in my activity. The intent returned was for picking an image of the type image/*. Works well for me!

Uri imageUri = intent.getData();
                String[] orientationColumn = {MediaStore.Images.Media.ORIENTATION};
                Cursor cur = managedQuery(imageUri, orientationColumn, null, null, null);
                int orientation = -1;
                if (cur != null && cur.moveToFirst()) {
                    orientation = cur.getInt(cur.getColumnIndex(orientationColumn[0]));
                }  
                Matrix matrix = new Matrix();
                matrix.postRotate(orientation);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文