1. 使用`bmptoduet`库:
```python
from bmptoduet import BMP
bmp_file_path = 'path/to/your/image.bmp'
bmp_image = BMP(bmp_file_path)
width, height = bmp_image.width, bmp_image.height
print(f"图片宽度: {width}, 图片高度: {height}")
2. 使用`PIL`(Python Imaging Library)库(Pillow分支):```pythonfrom PIL import Image
image = Image.open('image.bmp')
width, height = image.size
print(f"图片宽度: {width}, 图片高度: {height}")
3. 使用`numpy`和`PIL`结合:

```python
import numpy as np
from PIL import Image
img = Image.open('example.bmp')
img_arr = np.array(img)
4. 使用`struct`模块读取BMP文件头信息:```pythonimport struct
with open('filename', 'rb') as file:
header = file.read(54)
file_size_byte = file.read(4)
file_ofset_byte = file.read(4)
file_wide_byte = file.read(4)
file_height_byte = file.read(4)
file_bitcount_byte = file.read(4)
f_size, = struct.unpack(' f_ofset, = struct.unpack(' ```
5. 使用`pybmp`库:
```python
from pybmp import BMP
image = BMP('my_image.bmp')
width = image.width
height = image.height
print(f"图像宽度: {width}, 图像高度: {height}")
pixels = image.pixels
print(f"像素数据: {pixels[:10]}")
请确保在尝试读取文件时,提供的文件路径是正确的,否则可能会抛出异常。如果需要进一步处理图像数据,比如调整大小、旋转或保存,可以使用Pillow库提供的方法。
