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

问题描述 投票:-1回答:1

就我而言,我有横向位图。现在我想将此图像设置为纵向模式。还设置图像的背景。如何将此图像设置为纵向而无划痕。我可以为背景添加画布并制作位图吗?

android image bitmap android-bitmap
1个回答
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

© www.soinside.com 2019 - 2024. All rights reserved.