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

#1 2012-12-08 11:02:56

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Image in Squeak from data

In Squeak, if I have the data for a PNG image, how can I put it into an ImageFrameMorph?

Using:

Code:

t7 _ (HTTPSocket httpGet: 'http://' , msServer , '/getavatar/' , t1) contents.
    t8 _ ImageFrameMorph new initFromForm: t7.

does not seem to work.


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

#2 2012-12-08 13:04:09

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: Image in Squeak from data

I assume it has something to do with PNGReadWriter.


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#3 2012-12-08 15:32:37

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

Re: Image in Squeak from data

PNGReadWriter createAFormFrom: t7

assuming you're talking about a PNG... now I forgot what we used.

Offline

 

#4 2012-12-08 22:37:53

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Re: Image in Squeak from data

I'm now trying this:

Code:

t7 _ (HTTPSocket httpGet: 'http://' , msServer , '/getavatar/' , t1) contents.
    scratchFrame write: t7 toFile: 'test.png'.
    t8 _ (FileStream readOnlyFileNamed: 'test.png') binary.
    t9 _ ImageReadWriter formFromStream: t8.
    t8 close.
    t10 _ ImageFrameMorph new initFromForm: t9.
    body addMorph: t10.

but it still doesn't work.


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

#5 2012-12-08 22:44:23

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Re: Image in Squeak from data

Trying

Code:

t7 _ (HTTPSocket httpGet: 'http://' , msServer , '/getavatar/' , t1) contents.
    scratchFrame write: t7 toFile: 'test.png'.
    t8 _ PNGReadWriter createAFormFrom: 'test.png'.
    t9 _ ImageFrameMorph new initFromForm: t8.

doesn't work either. It says that t8 is of type PNGReadWriter, not of the form type.


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

#6 2012-12-09 04:32:52

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

Re: Image in Squeak from data

it's right. Take the first value of t8 (t8 first) to get the image.

Also, I don't see why you're writing to a file! createAFormFrom wants a stream (which is actually precisely t7), not a string! The latter will give you a pretty bad image.

Offline

 

#7 2012-12-09 09:54:08

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Image in Squeak from data

LS97 wrote:

it's right. Take the first value of t8 (t8 first) to get the image.

Also, I don't see why you're writing to a file! createAFormFrom wants a stream (which is actually precisely t7), not a string! The latter will give you a pretty bad image.

…and then stop calling your temporary variables tn.


nXIII

Offline

 

#8 2012-12-09 09:57:50

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Re: Image in Squeak from data

nXIII wrote:

LS97 wrote:

it's right. Take the first value of t8 (t8 first) to get the image.

Also, I don't see why you're writing to a file! createAFormFrom wants a stream (which is actually precisely t7), not a string! The latter will give you a pretty bad image.

…and then stop calling your temporary variables tn.

Squeak automatically does that. I can't do anything about it.


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

#9 2012-12-09 10:06:09

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Image in Squeak from data

jvvg wrote:

nXIII wrote:

LS97 wrote:

it's right. Take the first value of t8 (t8 first) to get the image.

Also, I don't see why you're writing to a file! createAFormFrom wants a stream (which is actually precisely t7), not a string! The latter will give you a pretty bad image.

…and then stop calling your temporary variables tn.

Squeak automatically does that. I can't do anything about it.

Squeak automatically does that when you're missing a .changes file, because it has nowhere to put the method sources.


nXIII

Offline

 

#10 2012-12-09 11:59:35

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Re: Image in Squeak from data

nXIII wrote:

jvvg wrote:

nXIII wrote:


…and then stop calling your temporary variables tn.

Squeak automatically does that. I can't do anything about it.

Squeak automatically does that when you're missing a .changes file, because it has nowhere to put the method sources.

So if I make a .changes file, it won't automatically do that? I'll try that.


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

Board footer