如何使用Python Matplotlib将正方形图像像素化为256个大像素? 要使用Python将正方形图像像素化为256个大像素,可以执行以下步骤- 设置图形大小并调整子图之间和周围的填充。 打开并识别给定的图像文件。 调整图像样本的大小。 制作结果图像并调整其大小。 保存结果图像。 示例 from PIL import Image from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True img = Image.open("bird.png") imgSmall = img.resize((16, 16), resample=Image.BILINEAR) result = imgSmall.resize(img.size, Image.NEAREST) result.save('result.png') PythonCopy 输入图像 输出图像