256灰阶图bmp文件32位深度(python)

from PIL import Image
def print_hi(name):
    # 在下面的代码行中使用断点来调试脚本。
    print(f'Hi, {name}')  # 按 Ctrl+F8 切换断点。


# 按间距中的绿色按钮以运行脚本。
if __name__ == '__main__':


    # 定义彩条测试图的尺寸和颜色数
    width = 720
    height = 480
    segments = 16
    segments_h = 16
    color = -1
    # 创建一个空白图像
    image = Image.new("RGBA", (width, height))

    # 计算每个段的宽度
    segment_width = int(width / segments)
    segment_height = int(height / segments_h)

    # 生成彩条图像
    for i in range(segments):
        start = i * segment_width
        end = (i + 1) * segment_width
        for h in range(segments_h):
            start_h = h * segment_height
            end_h = (h + 1) * segment_height
 #           color = int(i * (255 / (segments - 1)))
            color = color + 1
            for y in range(start_h, end_h):
                for x in range(start, end):
                    if y == start_h:
                        image.putpixel((x, y), (0, 0, 0, 255))
                    elif x == start:
                        image.putpixel((x, y), (0, 0, 0, 255))
                    else:
                        image.putpixel((x, y), (color, color, color, 255))


    # 保存彩条测试图
    image.save("gray_bar_480p.bmp", format="BMP", bits=32)

    # 显示彩条测试图
    image.show()

  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值