为什么Bitmap.createBitmap()旋转图像?

时间:2019-05-23 10:42:15

标签: android image-processing android-bitmap

我有一张图片,需要使用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();

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

enter image description here

但是,我尝试过类似的事情。

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();
}

我使用矩阵形成了以下图像。 enter image description here

如您所见,我的 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

0 个答案:

没有答案
相关问题