Embedding images (from newbie)
[1/5] from: ronald:gruss:libertysurf at: 8-Aug-2001 11:31
Hi Rebolers,
I've already seen those embedded images (like "polished" in Carl's VID Usage)
How could I convert an image file into "text code"
Thanks to all of you, the list is very rich !!!
Ronald
[2/5] from: chris:ross-gill at: 8-Aug-2001 10:06
Hi Ronald,
> I've already seen those embedded images (like "polished" in
> Carl's VID Usage)
>
> How could I convert an image file into "text code"
The image! datatype takes the following form:
make image! [size data]
The size is, of course, a pair!, eg. 240x180 and the data is binary!.
img: make image! [2x2 #{0000CC0000CC0000CC0000CC}]
The data equates to colours similar to web hex values, except the order is
BBGGRR. So the above example would give you 4 red pixels (B = 00 or 0, G 00 or 0 and
R = CC or 204).
To load external image data, use 'load or 'load-image (the latter caches
images from the web/reb):
img: load-image http://www.ross-gill.com/r/rg-rim.png
probe img
To put the image into the clipboard in REBOL format,
save clipboard:// img
Hope that's enough to get you started.
- Chris
[3/5] from: agem:crosswinds at: 8-Aug-2001 20:10
RE: [REBOL] Re: Embedding images (from newbie)
I think Ronald refers to embedding
*.jpg's in scripts, not unpacked images?
one can do stuff like
my-image: load #{lots-mysterios-characters-representing-a-jpeg}
where these characters are comming from
write clipboard:// enbase read/binary my-jpg
then you can paste the contents between the
#{}
(can be a very long line, but its allowed to
line-break enbased code.)
Carl posted a script a while ago which collected
some images and scripts into one script with embedded data.
-Volker
..)
[chris--ross-gill--com] wrote:
[4/5] from: ljurado:bariloche:ar at: 8-Aug-2001 23:46
Ranald :
This is post to ALLY list from Carl Sassenrath:
Luis
-----------------------------------------------------------------------
Some types of scripts can benefit from embedded images. For instance, if you
want use nice arrows for next and back on buttons, such as a scroll bar.
Here's how:
1. Save your image as a REBOL binary:
system/options/binary-base: 64
save %image.r read/binary %image.gif
2. Paste image.r into your script, adding a load
to convert it into an image datatype.
image: load 64#{ ....
}
Optimizations:
1. Use compress on the image when you save it out.
save %image.r compress read/binary %image.gif
then the load becomes:
image: load decompress 64#{ ....
2. If you compress the BMP, it can be smaller than
compressing the GIF. (But, more research must
be done on this.)
3. If you don't need to use the image immediately,
don't decompress or load it. Just assign it to
a word or keep it in a list until you need to
display it.
4. You can reuse the SAME image multiple times.
For instance, an arrow pointing up can point
down if you do a VFLIP on it. Or, it can go
right and left with a ROTATE. This can save
many bytes.
-Carl
[5/5] from: ronald:gruss:libertysurf at: 9-Aug-2001 10:34
Thanks to all of you, that's just what I needed.
Rebol is fantastic
I'm learning a lot on the list, hope I'll be able to help somebody else ...
when I'll be better ! ;-)
Ronald