首页 > 解决方案 > 为什么 Bitmap.createBitmap() 会旋转我的图像?

问题描述

我有一张需要使用 TFLite 在 Android 客户端上进行手写识别的图像。

为了测试这一点,我剪切了图像的一些部分并将它们传递给模型,但尽管模型的准确度为 90%,但准确度却很差。

为了进一步调试,我正在检查我的切割部分是否正确。以下代码是我用来裁剪图像的代码。

Bitmap test = Bitmap.createBitmap(src, 494,213,30, 33);

当我这样做时,

new Thread() {
        @Override
        public void run() {
            try (FileOutputStream out = new FileOutputStream(path+"/test.jpg")) {
                (test).compress(Bitmap.CompressFormat.JPEG, 100, out); // bmp is your Bitmap instance
                // PNG is a lossless format, the compression factor (100) is ignored
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }.start();

图像被正确保存到我的存储中。

在此处输入图像描述

但是,我尝试了这样的事情。

for(int i =0;i<30;i++){
     for(int j=0;j<33;j++){
        System.out.print(Color.red(test.getPixel(i,j))+" ");
     }
     System.out.println();
}

我使用了矩阵并形成了以下图像。 在此处输入图像描述

如您所见,我原始的1部分位图已旋转。

有人可以解释为什么会这样吗?一些替代方法也会有所帮助

提前致谢。

更新: 我尝试了以下

ExifInterface ei= null;
try {
   ei = new ExifInterface(root+"/test.jpg");
} catch (IOException e) {
   e.printStackTrace();
}
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                    ExifInterface.ORIENTATION_UNDEFINED);
System.out.println("Orientation is "+orientation);

我的输出是:

方向为 0

标签: androidimage-processingandroid-bitmap

解决方案


推荐阅读