import os
import cv2
img = cv2.imread("./favorite.png", cv2.IMREAD_UNCHANGED)
print("image_shape: ", img.shape)
# 图像信息
width = img.shape[0]
height = img.shape[1]
size = width * height
file = open("./output.cpp", "w")
file.writelines("DWORD pBuf[" + str(size) + "] = {\n")
print(img[0][0])
print(img[0][1])
print(img[0][2])
print(img[0][3])
print(img[0][4])
buf = ""
for i in range(0, height):
buf += "\t"
for j in range(0, width):
b = img[i][j][0]
g = img[i][j][1]
r = img[i][j][2]
a = img[i][j][3]
value = a << 24 | r << 16 | g << 8 | b
value &= 0xffffffff
buf += "0x{:08X}, ".format(value)
#print("0x{:08X}, ".format(value))
buf += "\n"
file.write(buf)
file.writelines("};")
file.close()
输出十六进制 argb 数组