I'm trying to convert an image to grayscale after the user clicks on the original image but I can't get it to work. Here is the entire code I've written.
from PIL import Image
from pathlib import Path
import win32api
data_folder = Path("H:/Elijah Kroeber/Images")
file = data_folder / "nature.jpg"
try:
img = Image.open(file)
except IOError:
pass
with Image.open(file) as image:
width, height = image.size
win = image.size
state_left = win32api.GetKeyState(0x01)
while True:
a = win32api.GetKeyState(0x01)
if a != state_left:
for row in range(img.getHeight()):
for col in range(img.getWidth()):
p = img.getPixel(col, row)
aver = (p.getRed() + p.getGreen() + p.getBlue())/3
newred = aver
newgreen = aver
newblue = aver
newpixel = Image.Pixel(newred, newgreen, newblue)
img.setPixel(col, row, newpixel)
img.draw(win)
Comments
Post a Comment