如何将位图图像的横向设置为纵向

时间:2018-11-02 07:40:16

标签: android image bitmap android-bitmap

就我而言,我有风景位图。现在,我想将此图像设置为纵向模式。还设置图像背景。如何将此图像设置为纵向而不会刮擦。我可以添加画布作为背景并制作位图吗?

1 个答案:

答案 0 :(得分:0)

您可以在setRotate之后使用setRectToRect,并且postTranslate不会旋转图像,而是以纵向模式显示同一图像。

 Bitmap bmp = decodeFile(new File(created_folder + File.separator + "pic00" + (k + 1) + ".jpg"));
        Matrix matrix = new Matrix();
         float scale = 1024/bmp.getWidth();
        float xTranslation = 0.0f, yTranslation = (720 - bmp.getHeight() * scale)/2.0f;
        RectF drawableRect = new RectF(0, 0, bmp.getWidth()-100,
                bmp.getHeight()-100);

        RectF viewRect = new RectF(0, 0, bmp.getWidth(),
                bmp.getHeight());

            matrix.setRectToRect(drawableRect, viewRect, Matrix.ScaleToFit.CENTER);
            matrix.setRotate(90, bmp.getWidth(), bmp.getHeight());
            matrix.postTranslate(xTranslation, yTranslation);
            matrix.preScale(scale, scale);

有关更多详细信息,请浏览android开发人员文档 http://developer.android.com/reference/android/media/ExifInterface.html