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

#1 2011-05-15 06:39:19

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

save picture of stage

Does anyone know where the method for this is in the browser? I really want to try and change the export to be a PNG not the current JPEG or BMP I think it is - I lose a lot of image quality! Thanks!


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

Offline

 

#2 2011-05-15 06:45:05

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: save picture of stage

ScratchObjects » ScratchStageMorph » event handling » stageShot
but that doesn't give the file type.  hmm

Offline

 

#3 2011-05-15 06:58:51

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

Re: save picture of stage

You're right  sad  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?


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

Offline

 

#4 2011-05-15 07:04:37

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: save picture of stage

sparks wrote:

You're right  sad  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.  hmm
How long is 60 seconds anyways!?

Offline

 

#5 2011-05-15 07:07:25

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

Re: save picture of stage

t1 size > 0 ifTrue: [self exportFileName: t1]

Is at the bottom. What if t1 was set to a PNG format just above that line?


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

Offline

 

#7 2011-05-15 07:14:36

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

Re: save picture of stage

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$

Code:

    | 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: t5

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

Offline

 

#8 2011-05-15 07:16:09

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: save picture of stage

Maybe if you edit Scratch-UI-Dialogs >> ScratchFileChooserDialog?

Offline

 

#9 2011-05-15 07:36:13

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

Re: save picture of stage

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:

Code:

t1 = 'stage' ifTrue: [t2 _ ImageMedia new form: (self ownerThatIsA: ScratchStageMorph) stageShotForm].

Last edited by sparks (2011-05-15 07:36:21)


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

Offline

 

#10 2011-05-15 07:46:23

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: save picture of stage

sparks wrote:

t1 size > 0 ifTrue: [self exportFileName: t1]

Does this not suggest to have a look at the exportFileName: method?  smile

Offline

 

#11 2011-05-15 07:49:33

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: save picture of stage

LS97 wrote:

sparks wrote:

t1 size > 0 ifTrue: [self exportFileName: t1]

Does this not suggest to have a look at the exportFileName: method?  smile

Of course it does.  tongue

Offline

 

#12 2011-05-15 08:11:03

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

Re: save picture of stage

LS97 wrote:

sparks wrote:

t1 size > 0 ifTrue: [self exportFileName: t1]

Does this not suggest to have a look at the exportFileName: method?  smile

yup. I can't find it...


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

Offline

 

#13 2011-05-15 08:19:09

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

Re: save picture of stage

Found it!

Code:

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: t3

I 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)


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

Offline

 

#14 2011-05-15 08:20:15

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: save picture of stage

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

 

#15 2011-05-15 09:08:10

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

Re: save picture of stage


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

Offline

 

#16 2011-05-15 17:20:56

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

Re: save picture of stage

Ideas anyone else?


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

Offline

 

#17 2011-05-16 03:33:12

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: save picture of stage

Well I cant help, but could you not print-screen your PC, crop the stage and save it as PNG?


You can now reach me on Twitter @johnnydean1_

Offline

 

#18 2011-05-16 03:54:51

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: save picture of stage

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,  wink

Offline

 

#19 2011-05-16 11:33:09

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: save picture of stage

Fine, I'll dust off my copy of Bingo and try to find a solution.  smile

Offline

 

#20 2011-05-16 11:37:32

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: save picture of stage

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

 

#21 2011-05-16 11:38:36

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: save picture of stage

Does the 'writePNGFileNamed:' method exists?


You can now reach me on Twitter @johnnydean1_

Offline

 

#22 2011-05-16 11:39:40

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: save picture of stage

johnnydean1 wrote:

Does the 'writePNGFileNamed:' method exists?

Yes, I checked before posting that.

Offline

 

#23 2011-05-16 11:42:14

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: save picture of stage

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.


You can now reach me on Twitter @johnnydean1_

Offline

 

#24 2011-05-16 11:45:11

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: save picture of stage

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

 

#25 2011-05-16 11:49:20

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: save picture of stage

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?


You can now reach me on Twitter @johnnydean1_

Offline

 

Board footer