image management in Squeak

goran.krampe at bluefish.se goran.krampe at bluefish.se
Mon Jan 12 09:54:11 UTC 2004


=?gb2312?q?ye=20juan?= <yejuan_1204 at yahoo.com.cn> wrote:
> Hi,
>    I have a picture named "person.gif" in disk. Now I
> want to read it into Squeak and save it as an instance
> object of a class "Photo".

First I searched for a class ("find class" in browser) with "gif" in
them. Found "GIFReadWriter", then looked at the class side (to see how
to create one) - not much there. Ok, let's look up the inheritance -
looked in ImageReadWriter. Found method #formFromFileNamed:. Ok, tested
to do inspect it on this:

ImageReadWriter formFromFileNamed: 'image.gif'

Where I had 'image.gif' in the working directory. Ok, it worked and I
can see an instance of a ColorForm. Ok, so the class Form and ColorForm
etc are the classes for bitmap images in Squeak. This is the instance
you would hold in an instvar in your "Photo" class.

Let's see how to see the darn thing on the screen. I knew that there are
Morph classes for this so I quickly found SketchMorph and ImageMorph,
don't remember the details on differences. Anyway, ImageMorph has a
method to change the Form that it shows - so let's just create one,
smack in the Form and show the morph in the world:

| aForm |
aForm := ImageReadWriter formFromFileNamed: 'BuildingSBlog.gif'.
ImageMorph new newForm: aForm; openInWorld

Hope this helps.

Cheers, Göran



More information about the Squeak-dev mailing list