【问题标题】:I want to rotate image which is generated from its thumbnail我想旋转从其缩略图生成的图像
【发布时间】:2025-12-22 00:40:10
【问题描述】:
Bitmap bMap = ThumbnailUtils.createVideoThumbnail(videopathbundle,
            MediaStore.Images.Thumbnails.MICRO_KIND);    

在上面的代码中,我能够从视频文件路径中获取缩略图。但是图像设置为横向模式。所以我现在想旋转并以纵向或纵向显示图像。我尝试了其他方法,但无法获得旋转相同的宽度和高度。

朋友们请帮帮我。

我将其更改为可绘制,然后尝试旋转图像,但在计算宽度和高度时出现错误。

Drawable d= new BitmapDrawable(getResources(), bMap);
Bitmap finalThumb = ((BitmapDrawable)d).getBitmap();
Bitmap bmresult = Bitmap.createBitmap(finalThumb);
Canvas tempcanvas = new Canvas(bmresult);
tempcanvas.rotate(90);
tempcanvas.drawBitmap(bmresult, 0, 0, null);
Matrix matrix = new Matrix();
matrix.postRotate(90);
Imageview videoThumb.setImageBitmap(bmresult );

【问题讨论】:

标签: android android-imageview android-drawable bitmapfactory android-bitmap


【解决方案1】:

使用以下方法根据特定角度旋转位图

public static Bitmap Rotate(Bitmap _input, float _angle)
{
      Matrix matrix = new Matrix();
      matrix.postRotate(_angle);
      return Bitmap.createBitmap(_input, 0, 0, _input.getWidth(), _input.getHeight(), matrix, true);
}

for call Rotate(myBmp,90);

【讨论】:

  • _input 指的是位图或其位置。因为无法获取位置,所以只能使用位图对象
  • 此方法获取位图并旋转然后返回位图,