【问题标题】:win32api: get bitmap palettewin32api:获取位图调色板
【发布时间】:2011-01-05 15:39:30
【问题描述】:

我基本上是在做this 但对于 8 位。我可以使用“P”作为模式位正确获取位图位。但是,我有所有这些位图位,但没有调色板——PIL 只使用默认的灰度调色板。如何从图像中获取正确的调色板?

【问题讨论】:

    标签: python image winapi pywin32 8-bit


    【解决方案1】:

    我不知道如何将 Windows API 调用转换为 Python,也不知道如何更新 PIL 中的调色板,但这里可以。

    Windows 位图没有附加调色板。调色板被选入DC并与保留的系统颜色合并;然后使用当前选择的调色板显示位图。

    如果您有 DC,则可以使用 GetSystemPaletteEntries 获取当前实现的调色板。

    【讨论】:

      【解决方案2】:

      这可行,返回一个与 PIL 兼容的调色板:

      import ctypes, win32gui
      def getSystemPalette():
          hwnd = win32gui.GetDesktopWindow()
      
          hwndDC = win32gui.GetWindowDC(hwnd)
      
          buff = ctypes.c_buffer("0"*(256*4)) #R, G, B, and flags
          ctypes.windll.gdi32.GetSystemPaletteEntries(hwndDC, 0, 256, buff)
      
          win32gui.ReleaseDC(hwnd, hwndDC)
      
          #ignore every 4th entry which is the flags
          res = [ord(x) for i,x in enumerate(buff) if i%4 != 3]
          return res
      

      【讨论】:

        猜你喜欢
        • 2013-09-15
        • 2010-11-09
        • 2021-12-03
        • 1970-01-01
        • 1970-01-01
        • 2023-03-25
        • 2018-09-05
        • 2011-04-16
        • 1970-01-01
        相关资源
        最近更新 更多