Warning: file_get_contents() [function.file-get-contents]: SSL: 远程主机强迫关闭了一个现有的连接。 in D:\wwwroot\huidong\wwwroot\function.inc.php on line 884

Warning: file_get_contents(https://whois.pconline.com.cn/jsLabel.jsp?ip=127.0.0.1) [function.file-get-contents]: failed to open stream: HTTP request failed! in D:\wwwroot\huidong\wwwroot\function.inc.php on line 884
py 将图片加载为 cpp 数组(保留 alpha 通道) - huidong

huidong

首页 | 会员登录 | 关于争取 2022 寒假做出汇东网 Ver3.0.0 !
搜索文章


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 数组



返回首页


Copyright (C) 2018-2024 huidong