PIL转换后的图像中像素的RGB值不同

时间:2019-08-08 11:21:38

标签: python image base64 python-imaging-library

我已将base64中的图像发送到服务器,并将其保存在.jpeg中。我将图像转换为RGB并花了一个像素检查它的RGB值。同时拍摄上传的图像,将其放入Gimp,找到该点并检查其值。这是不同的。不多,但是。我想从移动应用程序发送该值,该应用程序会检查该点并向我发送该值,以便我可以再次检查它以确保它没有损坏。重要的是图像不会因保存而失去质量,因为保存后值会有所不同。这是我的代码。

def validate_image(instance):
    img = Image.open(instance.file)
    rgb_img = img.convert('RGB')
    for point in instance.rgb_points.all():
        if point.x >= img.width or point.y >= img.height:
            raise PointOutOfRangeError
        key = (point.x, point.y)
        saved_rgb = int(('%02x%02x%02x' % rgb_img.getpixel(key)), 16)
        if saved_rgb != point.rgb:
            return False
    return True

我不确定为什么save_rgb的值不同于point.rgb wchich是数据库中保存的point的rgb值。 (与Gimp的值相同)

0 个答案:

没有答案