图像方向

问题描述 投票:0回答:2

我已经研究了很长时间。

我需要知道如何通过从元数据标签读取图像来获得图像的方向。

我看过Exif和其他第三方代码。我只是想通过阅读元数据标签来学习如何做。

我有一个读取IIOMetadata的代码,但是图像尺寸标签或方向只会说正常。

有什么建议吗?

java image orientation
2个回答
0
投票

https://github.com/exif-js/exif-js/blob/master/exif.js

function base64ToArrayBuffer (base64) {
    base64 = base64.replace(/^data\:([^\;]+)\;base64,/gmi, '');
    var binaryString = atob(base64);
    var len = binaryString.length;
    var bytes = new Uint8Array(len);
    for (var i = 0; i < len; i++) {
        bytes[i] = binaryString.charCodeAt(i);
    }
            return bytes.buffer;
}

reader.onload = function (e) {
    var image = new Image();
    image.src = e.target.result;
    exif = EXIF.readFromBinaryFile(base64ToArrayBuffer(e.target.result));
    console.log(exif.Orientation, exif.Make);

0
投票

您可以使用我的库Scrimage(2013年第一个发行版,在撰写本文时,最新版本为2020年2月),其中包含AWT并提供了许多帮助程序功能。

  ImmutableImage image = ImmutableImage.loader().fromBytes(bytes);
  Orientation o = image.metadata.orientation();
© www.soinside.com 2019 - 2024. All rights reserved.