如何在 python 中将 24 色 bmp 图像转换为 16 色 bmp
How to convert a 24 color bmp image to 16 color bmp in python
对于我当前的任务,我需要将 24 色 bmp 文件转换为 16 色 bmp 文件。并打印 pdf 文件中的图像。我厌倦了使用 PIL 模块,但它对我没有帮助。
from PIL import Image
path = r'C:\Display_Icon_Testing\Captured_Images\Impl_Modulation_Screen.bmp'
im = Image.open(path)
print im
im1 = Image.open(path).convert('P')
print im1
请帮我解决这个问题。
下面的代码将读取 PIL 可以理解的任何格式的图像,将其转换为 16 色,并将其保存为 PDF 文件。默认情况下,PIL 在将 24 位图像转换为基于调色板的图像时使用 Floyd-Steinberg dithering 来提高图像质量。
我正在使用 PIL 的 Pillow 分支,因为不再维护原始 PIL,但此代码应该可以在原始 PIL 或 Pillow 上正常工作。
from PIL import Image
iname = 'test.bmp'
oname = 'test.pdf'
img = Image.open(iname)
newimg = img.convert(mode='P', colors=16)
newimg.save(oname)
对于我当前的任务,我需要将 24 色 bmp 文件转换为 16 色 bmp 文件。并打印 pdf 文件中的图像。我厌倦了使用 PIL 模块,但它对我没有帮助。
from PIL import Image
path = r'C:\Display_Icon_Testing\Captured_Images\Impl_Modulation_Screen.bmp'
im = Image.open(path)
print im
im1 = Image.open(path).convert('P')
print im1
请帮我解决这个问题。
下面的代码将读取 PIL 可以理解的任何格式的图像,将其转换为 16 色,并将其保存为 PDF 文件。默认情况下,PIL 在将 24 位图像转换为基于调色板的图像时使用 Floyd-Steinberg dithering 来提高图像质量。
我正在使用 PIL 的 Pillow 分支,因为不再维护原始 PIL,但此代码应该可以在原始 PIL 或 Pillow 上正常工作。
from PIL import Image
iname = 'test.bmp'
oname = 'test.pdf'
img = Image.open(iname)
newimg = img.convert(mode='P', colors=16)
newimg.save(oname)