简答:
对于 iOS,您需要以相反的顺序读取这些字节以获得正确的值。另外,您错误地读取了 24 位(3 个字节)而不是 16 位(2 个字节)。或者,也许您正在提取 2 个字节,但不知何故,您的字节在末尾添加了一个额外的“零”字节??
您可以尝试在 If 语句中使用 OR 检查来检查两个 Endian 类型等效项。既然 Android = 3 会变成 iOS = 768,你可以试试:
if (orient_val == 3 || orient_val == 768)
{ /* do whatever you do here */ }
PS:1==2562==5123==7684==10245==12806==15367==17928==2048,9==2304
长版:
Android 处理器通常将字节读取为 Little Endian。 Apple 处理器将字节读取为 Big Endian。基本上一种类型是从右到左阅读,另一种是从左到右阅读。其中 Android 的 ABCD 在 iOS 中变为 DCBA。
一些提示:
-
Lil' E 中的 3 为(2 个字节)写为
00+03... 但在
Big E写成03+00。
- 问题是,如果您不适应并只是阅读
03 00 就好像它仍然是 LE,那么您会得到 768。
- 最糟糕的是,不知何故,您将其阅读为
03 00 00,这给了您
196608。
- 另一个是
06 00 00 给你 393216 而不是为 1536 阅读 60 00。
- 修复您的代码以在末尾删除额外的
00 字节。
您在 Android 上很幸运,因为我怀疑它需要 4 个字节而不是 2 个字节。所以00 00 06 被读作00 00 00 06,因为x000006 和x00000006 意思相同=6。
无论如何,要正常解决此问题,您只需告诉 AS3 将您的 Jpeg 字节视为 Big Endian,但这现在可以修复 iOS,但随后会在 Android 上破坏它。
一个快速简单的解决方案是检查你得到的数字是否大于 1 位,如果是,那么你假设应用程序在 iOS 上运行并尝试反向排序以查看现在的结果是 1 位数。所以..
注意:代码中显示的选项 B 是有风险的,因为如果你有错误的数字,你会得到错误的结果。你知道电脑..“bad input = bad output; do Next();”
import flash.utils.ByteArray;
var Orientation_num:uint = 0;
var jpeg_bytes:ByteArray = new ByteArray(); //holds entire JPEG data as bytes
var bytes_val:ByteArray = new ByteArray(); //holds byte values as needed
Orientation_num = 2048; //Example: Detected big number that should be 8.
if (Orientation_num > 8 ) //since 8 is maximum of orientation types
{
trace ("Orientation_num is too big : Attempting fix..");
//## A: CORRECT.. Either read directly from JPEG bytes
//jpeg_bytes.position = (XX) - 1; //where XX is start of EXIF orientation (2 bytes)
//bytes_val = jpeg_bytes.readShort(); //extracts the 2 bytes
//## B: RISKY.. Or use the already detected big number anyway
bytes_val.writeShort(Orientation_num);
//Flip the bytes : Make x50 x00 become x00 x50
var tempNum_ba : ByteArray = new ByteArray(); //temporary number as bytes
tempNum_ba[0] = bytes_val[1];
tempNum_ba[1] = bytes_val[0];
//tempNum_ba.position = 0; //reset pos before checking
Orientation_num = tempNum_ba.readShort(); //pos also MOVES forward by 2 bytes
trace ("Orientation_num (FIXED) : " + Orientation_num);
}