ScratchObjects » ScratchStageMorph » event handling » stageShot
but that doesn't give the file type.
Offline
sparks wrote:
You're right
You know my low resolution logo test in my projects? I'm trying to get it high res and I have to print screen each frame in order to do so at the moment! Any idea how to change it to PNG?
I've seen that project.
No, I don't know how to change the filetype.
How long is 60 seconds anyways!?
Offline
Well then, it'd become a PNG file then.
Offline
Another avenue to pursue might be this one: This piece of code by MathWizz exports a sprite's costume to a file in PNG format. Could it be rewritten to do it with the stage instead?
export costume $String$ to file $String$
| 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
Maybe if you edit Scratch-UI-Dialogs >> ScratchFileChooserDialog?
Offline
I was hoping to find something in the code for Panther's "add costume [stage]" block. There's no file type specification where I found it at Scratch-Objects >> ScriptableScratchMorph>>looks ops>>addCostumeTyped:
t1 = 'stage' ifTrue: [t2 _ ImageMedia new form: (self ownerThatIsA: ScratchStageMorph) stageShotForm].
Last edited by sparks (2011-05-15 07:36:21)
Offline
sparks wrote:
t1 size > 0 ifTrue: [self exportFileName: t1]
Does this not suggest to have a look at the exportFileName: method?
Offline
LS97 wrote:
sparks wrote:
t1 size > 0 ifTrue: [self exportFileName: t1]
Does this not suggest to have a look at the exportFileName: method?
![]()
Of course it does.
Offline
Found it!
exportFileName: t1
| t2 t3 |
t2 _ self stageShotForm.
t2 depth <= 8
ifTrue:
[(t1 asLowercase endsWith: '.gif')
ifTrue: [t3 _ t1]
ifFalse: [t3 _ t1 , '.gif'].
GIFReadWriter putForm: t2 colorReduced8Bit onFileNamed: t3.
^ self].
(t1 asLowercase endsWith: '.bmp')
ifTrue: [t3 _ t1]
ifFalse: [t3 _ t1 , '.bmp'].
(t2 asFormOfDepth: 32)
writeBMPFileNamed: t3I attempted to replace both of them (not at the same time) with PNG and even when gif was not in there, it appeared to add it as a PNG
The way I read that code, if the depth of t2 <= 8 it will write it as a gif, otherwise it will write it as a bmp. No idea how to add png to that as I've already tried replacing
(t1 asLowercase endsWith: '.bmp')
ifTrue: [t3 _ t1]
ifFalse: [t3 _ t1 , '.bmp'].
(t2 asFormOfDepth: 32)
writeBMPFileNamed: t3
with
(t1 asLowercase endsWith: '.png')
ifTrue: [t3 _ t1]
ifFalse: [t3 _ t1 , '.png'].
(t2 asFormOfDepth: 32)
writePNGFileNamed: t3
Last edited by sparks (2011-05-15 08:22:25)
Offline
Did you solve?
EDIT: I remember that method! I tried to do the same thing and failed. ^^
Last edited by scimonster (2011-05-15 08:20:57)
Offline
Well I cant help, but could you not print-screen your PC, crop the stage and save it as PNG?
Offline
johnnydean1 wrote:
Well I cant help, but could you not print-screen your PC, crop the stage and save it as PNG?
That's what he does but it takes a while,
Offline
Fine, I'll dust off my copy of Bingo and try to find a solution.
Offline
So replacing the exportFileName: code doesn't work when replaced with this?
exportFileName: fileName
| form fName |
form _ self stageShotForm.
(fileName asLowercase endsWith: '.png')
ifTrue: [fName _ fileName]
ifFalse: [fName _ fileName, '.png'].
(form asFormOfDepth: 32) writePNGFileNamed: fName.
I will investigate further, but to me the code above seems completely legit. If that doesn't work, i don't know what will.
Offline
Does the 'writePNGFileNamed:' method exists?
Offline
johnnydean1 wrote:
Does the 'writePNGFileNamed:' method exists?
Yes, I checked before posting that.
Offline
Cracked it:
exportFileName: fileName
| form fName |
form _ self stageShotForm.
form depth <= 8 ifTrue: [
(fileName asLowercase endsWith: '.png')
ifTrue: [fName _ fileName]
ifFalse: [fName _ fileName, '.png'].
GIFReadWriter putForm: form colorReduced8Bit onFileNamed: fName.
^ self].
(fileName asLowercase endsWith: '.png')
ifTrue: [fName _ fileName]
ifFalse: [fName _ fileName, '.png'].
(form asFormOfDepth: 32) writeBMPFileNamed: fName.
Offline
johnnydean1 wrote:
Cracked it:
exportFileName: fileName
| form fName |
form _ self stageShotForm.
form depth <= 8 ifTrue: [
(fileName asLowercase endsWith: '.png')
ifTrue: [fName _ fileName]
ifFalse: [fName _ fileName, '.png'].
GIFReadWriter putForm: form colorReduced8Bit onFileNamed: fName.
^ self].
(fileName asLowercase endsWith: '.png')
ifTrue: [fName _ fileName]
ifFalse: [fName _ fileName, '.png'].
(form asFormOfDepth: 32) writeBMPFileNamed: fName.
It can't write a PNG called name.bmp or name.gif
Just physically impossible.
Last edited by scimonster (2011-05-16 11:45:36)
Offline
scimonster wrote:
johnnydean1 wrote:
Cracked it:
exportFileName: fileName
| form fName |
form _ self stageShotForm.
form depth <= 8 ifTrue: [
(fileName asLowercase endsWith: '.png')
ifTrue: [fName _ fileName]
ifFalse: [fName _ fileName, '.png'].
GIFReadWriter putForm: form colorReduced8Bit onFileNamed: fName.
^ self].
(fileName asLowercase endsWith: '.png')
ifTrue: [fName _ fileName]
ifFalse: [fName _ fileName, '.png'].
(form asFormOfDepth: 32) writeBMPFileNamed: fName.It can't write a PNG called name.bmp or name.gif
Just physically impossible.
Have you actually tried it?
Offline