Ask111
Ask111

Reputation: 11

How to use Python drawing line in a picture?

I have the following question:

Draw a green vertical line 1/3 of the way from the left edge, and a horizontal blue line 1/3 from the top. The vertical line should extend from the top of the image to the bottom; the horizontal line should extend from the left edge to the right edge. Using a loop and draw the lines pixel by pixel.

Draw a green vertical line from top to bottom, 1/3 of the way across a copy of edinburgh-castle.gif; also draw a horizontal blue line 1/3 of the way down the same image. Return the copy.

Thanks guys...I have really no idea how to do this.

Upvotes: 0

Views: 868

Answers (1)

trevorKirkby
trevorKirkby

Reputation: 1897

If you want to draw lines onto an image in a file, I would probably recommend you use the pygame library. It works fairly well for this sort of processing.

You can use the pygame.image.load() function to load the image as a Surface object, then use pygame.draw.line() function to draw the line onto the surface. Then you can save the modified surface back into the file with pygame.image.save().

Here are the pygame docs:

https://www.pygame.org/docs/

And if you haven't used it before you can download it right here:

http://www.pygame.org/download.shtml

Upvotes: 1

Related Questions