This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-06-21 00:46:17

kittenizator
Scratcher
Registered: 2010-01-13
Posts: 18

"Import image from file" block!

Thats the code for it! Copy and add to your remix of Scratch!!!


importImage: filename
    | t2 t3 t4 t5 t6 t7 |
    t2 _ filename.
    t5 _ OrderedCollection new.
    t4 _ FileDirectory extensionFor: t2 asLowercase.
    t4 = 'gif'
        ifTrue: [[t5 _ (GIFReadWriter new on: (FileStream readOnlyFileNamed: t2)) nextImageSet]
                ifError: [^ self]]
        ifFalse: [[t5 addLast: (Form fromFileNamed: t2)]
                ifError: [^ self]].
    t6 _ true.
    t5 do:
        [:t9 |
        t3 _ ImageMedia new form: (ScratchFrameMorph scaledFormForPaintEditor: t9).
        t7 _ self mediaNameFromFileName: t2 default: 'costume'.
        t3 mediaName: (self unusedMediaNameFromBaseName: (UTF8 withAll: t7)).
        media addLast: t3.
        t6
            ifTrue:
                [t6 _ false.
                self lookLike: t3 mediaName]].
    self updateMediaCategory

Offline

 

#2 2010-06-21 05:54:06

12three
Scratcher
Registered: 2008-06-12
Posts: 1000+

Re: "Import image from file" block!

Nice.  smile

Offline

 

#3 2011-01-22 16:27:28

BigDolphin
Scratcher
Registered: 2009-12-21
Posts: 81

Re: "Import image from file" block!

Thanks!


►►►►►►►►►♠"Thy fish no like thy Trout that deceives thy eye"♠◄◄◄◄◄◄◄◄◄

Offline

 

#4 2011-01-22 17:48:04

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: "Import image from file" block!

or:

Code:

self importMedia: t1

http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

Board footer