indeed there is. i cannot look it up for you right now, but Bingo uses that to export images from the paint editor (note the new little [export] button) and also has a
write [image] to file []
block which you could take the code from. it's not too hard, Scratch implemented a whole GIF and BMP read/writer.
Offline
sparks wrote:
I tried self exportMedia: t1 toFile: t2 with no luck.... same with exportCostume: t1 toFile: t2
ok, hold on while i go check in bingo. it's not that easy
-
At least 60 seconds have to pass between posts. Please wait a little while and try posting again.
Offline
pic exportFilename: fn for: self
that's the code taken exactly from the block.
ImageMedia new form: formName; mediaName: (self unusedMediaNameFromBaseName: self defaultImageMedia mediaName).
that's the code for creating an image media from a form. except, youll have to replace formName with the variable representing the form.
hope this helps
Offline
a code snippet would be
thepic _ ImageMedia new form: FORMNAME; mediaName: (self unusedMediaNameFromBaseName: self defaultImageMedia mediaName). thepic exportFilename: 'c:\pic.gif' for: self.
Offline
This is my code:
|thepic| thepic _ ImageMedia new form: t1 asString; mediaName: (self unusedMediaNameFromBaseName: self defaultImageMedia mediaName). thepic exportFilename: t2 for: self.
... It does not work
Offline
sparks wrote:
This is my code:
Code:
|thepic| thepic _ ImageMedia new form: t1 asString; mediaName: (self unusedMediaNameFromBaseName: self defaultImageMedia mediaName). thepic exportFilename: t2 for: self.... It does not work
![]()
that t1 asString doesn't look right.
is t1 supposed to be a form variable or a ScratchSkin member?
if it's the first option, take the asString away
Offline
t1 is a number (costume number) of the sprite, and in my experience squeak does not like working with number arguments, so the asString turns it into a string that squeak usually likes to work with. It does not work without the asString either.
Offline
sparks wrote:
t1 is a number (costume number) of the sprite, and in my experience squeak does not like working with number arguments, so the asString turns it into a string that squeak usually likes to work with. It does not work without the asString either.
that explains it. you will need some extra code in place of the t1 to actually retrieve the ImageMedia of that number. Sorry but I can't help you right now as it's pretty late here and I'm about to doze off on the keyboard. Good luck!
Offline
Lets see... *opens Scratch*
This should do it!
exportCostume: t1 toFile: t2
| t3 t4 t5 |
t3 _ nil.
(t1 isKindOf: String)
ifTrue:
[t3 _ self costumeFromName: t1.
t3
ifNil:
[t4 _ self interpretStringAsNumberIfPossible: t1.
t4 isNumber
ifTrue: [t3 _ self costumeFromName: (self costumeNameFromNumber: t4)]
ifFalse: [^ self]]].
t3
ifNil:
[t4 _ t1 asNumberNoError.
t3 _ self costumeFromName: (self costumeNameFromNumber: t4)].
t3 ifNil: [^ self].
t5 _ t2.
(t5 endsWith: '.png')
ifFalse: [t5 _ t5 , '.png'].
t3 form writePNGFileNamed: t5Offline