Embedding Graphics.
Well, my method doesn't use any compression, but it seems to work for
what I designed it for. And it's simple.
I make a directory for the icons I want to use in my program, put all my
icon bmp files in it, put this program in the directory and run it. It
creates a file called Icons.e that defines a global sequence of icons. Then
if for example, all of my icons have a bright white background and I want to
change it to light gray, all I have to do is open the include file in a text
editor and use it's search function to replace all occurrences of 15 with 7.
All of the icons are changed.
To use an icon, I can just say display_image( {x, y}, icon[UPARROW] )
or whatever. (constants for icons are named after their bmp file name)
Of course, I suppose everyone's already done this. But thought I might
as well share anyway.
Falkon
----------------------------------------------------------------------------
----
-- concat.ex
-- concatenates several small bmps into one include file
----------------------------------------------------------------------------
----
include graphics.e
include image.e
include file.e
include wildcard.e
sequence filelist1, filelist2
filelist1 = dir(current_dir())
filelist2 = {}
-- make a list of all *.bmp files in the directory
for count = 1 to length(filelist1) do
if wildcard_file("*.bmp", filelist1[count][1]) then
filelist2 = append(filelist2, filelist1[count][1])
end if
end for
filelist1 = {}
-- create include file "Icons.e" and write the list of constants
object result, fn
fn = open( "Icons.e", "w" )
if fn = -1 then abort(2) end if
puts( fn, "global sequence icon \n icon = repeat( {}, " )
print( fn, length(filelist2) )
puts( fn, " ) \n\n" )
puts( fn, "constant " )
for count = 1 to length(filelist2) do
if count = length(filelist2) then
puts( fn, "
"&filelist2[count][1..length(filelist2[count])-4]&" = "&sprintf("%d \n\n",
count))
else
puts( fn, "
"&filelist2[count][1..length(filelist2[count])-4]&" = "&sprintf("%d,\n",
count))
end if
end for
-- write image data
for count = 1 to length(filelist2) do
result = read_bitmap( filelist2[count] )
if atom(result) then
puts( 2, "Unable to open "&filelist2[count]&"\n" )
abort(1)
end if
puts( fn, "icon[" )
puts( fn, filelist2[count][1..(length(filelist2[count])-4)] )
puts( fn, "] = {\n" )
for count2 = 1 to length(result[2]) do
puts( fn, " " )
print( fn, result[2][count2] )
if count2 = length(result[2]) then
puts( fn, " \n" )
else
puts( fn, ", \n" )
end if
end for
puts( fn, " }\n\n" )
end for
close( fn )
----------------------------------------------------------------------------
----
----------------------------------------------------------------------------
----
|
Not Categorized, Please Help
|
|