read image files
Moderator: MSandro
read image files
It would be nice if you could read image files the same way you read text files. It looks like the read file block is already supposed to do that, but when I try, it returns an empty string.
Re: read image files
To read binary data, such as an image file, you need to pass 'true' as the second parameter. However, the block in the palette doesn't have a second parameter, although it should.
Here's a work-around for advanced users. First, enter developer mode using the right-click menu on the stage. Then, open a workspace using the "workspace..." command in the stage menu and enter:
like this:
Select that text and use alt-B (or cmd-B on a Mac) to turn the text into a block. You can also right-click on the selected text and select "blockify it..." from the menu. That will give you a block with a boolean second parameter set to true:
the result of this block is a "BinaryData" object. To access individual bytes in a BInaryData object, you need to use "byteAt". That's another block that is not in the palette, so you'll need to "blockify" that, too.
Finally, to decode PNG into a bitmap, you'll to blockify:
This might be more technical detail than you wanted, but I hope some of it is helpful.
Here's a work-around for advanced users. First, enter developer mode using the right-click menu on the stage. Then, open a workspace using the "workspace..." command in the stage menu and enter:
Code: Select all
readFile 'myFile' true
Select that text and use alt-B (or cmd-B on a Mac) to turn the text into a block. You can also right-click on the selected text and select "blockify it..." from the menu. That will give you a block with a boolean second parameter set to true:
the result of this block is a "BinaryData" object. To access individual bytes in a BInaryData object, you need to use "byteAt". That's another block that is not in the palette, so you'll need to "blockify" that, too.
Finally, to decode PNG into a bitmap, you'll to blockify:
Code: Select all
(readFrom (new 'PNGReader') data)