1
비트 맵 이미지 파일을 그레이 스케일로 변환하고 비트 맵 헤더 메소드를 사용하려고합니다. 나는 다음과 같은 코드를 가지고있다 :파이썬에서 비트 맵 헤더를 사용하는 방법은 무엇입니까?
BMHEADER = bytearray([
66, 77, # BM identifier
102, 117, 0, 0, # size of file in bytes
0, 0, 0, 0, # unused
54, 0, 0, 0, # offset where the data can be found
40, 0, 0, 0, # no. of bytes in DIB header from here
400, 0, 0, 0, # bitmap width in pixels
296, 0, 0, 0, # bitmap height in pixels
1, 0, # number of colour planes
24, 0, # number of bits per pixel (R=G=B=8 bits)
0, 0, 0, 0, # no compression
48, 117, 0, 0, # size of the raw data
18, 11, 0, 0, # horizontal resolution
18, 11, 0, 0, # vertical resolution
0, 0, 0, 0, # number of colours in the palette
0, 0, 0, 0, # all colours important
])
bmp = open(file, 'wb')
bmp.write(BMHEADER) # write header
pixel = bytearray([0, 0, 255]) # blue, green, red
for x in range (400):
for y in range (296):
나는 그것이 작동하도록 헤더를 설정하는 방법을 알아 내려고하고있다. 나는 너비와 높이가 정확이 알고 있지만 나는 다음과 같은 오류 받고 있어요 :
이에 대한0, 0, 0, 0, # all colours important
ValueError: byte must be in range(0, 256)
내가 라인에 배치해야합니다 어떤 값을 어떤 아이디어가 작업을?