Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+5 votes
asked in CSC201 Spring 2021 by (1 point)

1 Answer

+1 vote

You can't call the getWidth() method on a file name. The name of a file is simply a string of text (str data type), like "magic pink elephant" or "dragon wings", except that it happens to store the name of a file, like "gallery/owl.gif"

You also can't call .getWidth() on a file object. You can read data from a file object that was opened for reading, or you can write data to a file object that was opened for writing, but you can't get the width of a file objet.

Instead, you need to create an Image object, and then you CAN call the getWidth() method on that Image object. (The Image object will be creating using the image file name, so that the Image object know what file to load in order to create itself as an image...)

The slides today had an example of creating an Image object, or you can look it up in the Graphics reference PDF, or the graphics chapter of the Zelle textbook.

answered by (5.7k points)
...