- #1
ard12
- 2
- 0
Homework Statement
I'm writing a program that will do simple image editing with ppm files. I can only use the graphics library and things in there. No PIL or Image module.
My problem is that I get an error that says "couldn't recognize data in image file "sole.ppm"
I know for a fact it is a correct ppm file.
The Attempt at a Solution
Here's my code:
Code:
def main():
print("Image Editor")
print()
filename = input("name of image file: ")
print()
with open(filename) as f:
formatind = f.readline()
width, height = [int(x) for x in f.readline().split()]
colordepth = f.readline()
array = []
for line in f:
array.append([int(x) for x in line.split()])
win = GraphWin("Image Editor!", width, height)
image = Image(Point(100,100), filename)
Display(image, array, width, height, win)
inf.close()
win.getMouse()
win.close()
main()
And my display function looks like this:
Code:
def Display(image, array, width, height, win):
for i in range(width):
for j in range(0, height, 3):
colors = color_rgb(array[i][j], array[i][j+1], array[i][j+2])
image.setPixel(i, j, colors)
image.draw(win)
return
I just cannot figure out what's wrong with this. Any help would be great. Thanks