我在看Python程序设计时,里面有这样一段程序,目的就是把图片转换成负片,我在导入图片展示都正常,然后添加转换的时候发现Image.setPixel函数根本不工作,然后我debug发现set.Pixel没能对图像做任何处理
我怀疑过是我的setPixel函数格式不对,书中写的是(x,y,r,b,g)这样,我发现不行,又看有人用(x,y,color_rgb(r,g,b))结果就直接报错了
下面是我的代码,有大佬知道怎么解决吗,或者有其他的函数来设置像素
#导入图片
filename = "D:\\asus\\Documents\\daima\\code\\learn\\begin001.png"
image = GraphicsImage(filename)
#获取长宽并进行转换
x = image.width()
y = image.height()
for i in range(x) :
for j in range(y) :
r = image.getRed(i,j)
b = image.getBlue(i,j)
g = image.getGreen(i,j)
r1 = 255
b1 = 255
g1 = 255
z = image.setPixel(x,y,color_rgb(250,220,220))
r = image.getRed(i,j)
b = image.getBlue(i,j)
g = image.getGreen(i,j)
#展示图片
win = GraphicsWindow()
canvas = win.canvas()
canvas.drawImage(image)
win.wait()
我怀疑过是我的setPixel函数格式不对,书中写的是(x,y,r,b,g)这样,我发现不行,又看有人用(x,y,color_rgb(r,g,b))结果就直接报错了
下面是我的代码,有大佬知道怎么解决吗,或者有其他的函数来设置像素
#导入图片
filename = "D:\\asus\\Documents\\daima\\code\\learn\\begin001.png"
image = GraphicsImage(filename)
#获取长宽并进行转换
x = image.width()
y = image.height()
for i in range(x) :
for j in range(y) :
r = image.getRed(i,j)
b = image.getBlue(i,j)
g = image.getGreen(i,j)
r1 = 255
b1 = 255
g1 = 255
z = image.setPixel(x,y,color_rgb(250,220,220))
r = image.getRed(i,j)
b = image.getBlue(i,j)
g = image.getGreen(i,j)
#展示图片
win = GraphicsWindow()
canvas = win.canvas()
canvas.drawImage(image)
win.wait()