Conversion

Conversion

PSD 文件将大多数二进制字段以大端字节序存储。BigEndianBitConverter 直接从字节数组读取大端 32 位整数,适用于您自行处理原始字节的情况——例如,来自未识别的图像资源。


解码 32 位大端值

from aspose_psd_foss.bigendianbitconverter import BigEndianBitConverter

data = bytes([0x00, 0x00, 0x04, 0x10])  # example 4-byte big-endian field
value = BigEndianBitConverter.to_int32(data, 0)
print(f"Decoded value: {value}")  # 1040

to_int32(byte_array, offset) 从 offset 开始读取 4 个字节,并按最高有效字节在前的顺序合并它们。


技巧与最佳实践

  • BigEndianBitConverter 仅在此 FOSS 构建中提供 to_int32——对于 16 位或 64 位大端值,请使用 Python 内置的 int.from_bytes(data, byteorder="big") 手动解码。
  • 此实用工具用于您已经获取的原始字节(参见 Resources)——普通文档加载、编辑和保存从不直接需要它。

常见问题

问题原因修复
IndexError 调用 to_int32从 offset 开始的字节数组可用字节少于 4 个在调用之前检查 len(byte_array) >= offset + 4

FAQ

我在普通文档编辑时需要它吗?

不——它是一个用于您自行获取的原始字节的低层实用程序。典型的加载、编辑和保存(参见 Core API)从不直接需要它。


API Reference 概述

类/方法描述
BigEndianBitConverter.to_int32(byte_array, offset)解码一个大端序 32 位整数

另请参阅

 中文