I have a control which is a subclass of Canvas, which requires a few specific background images. How can I “embed” these images and make my control object self-contained, so that it can be saved as a single object and be used in various projects without having to move the image files around with it, cluttering up the Navigator?
Do not believe this is possilbe, as all images (and other “resources”) as stored in a single respository within the app (the structure varies between operating systems)… The best you can do is create folders in the IDE to reduce the clutter… (Note that these folders are an artificial construct, and are a means of organization within Xojo, but not within the compiled app, or disk file system)
Obviously it’s possible at some level, since all or most of the Xojo controls are canvas-based afaik, and we don’t have all their source images in the navigator, lol. Wasn’t this possible in RS by exporting things in .rbo format, or am I mis-remembering?
Convert the images to a string and store as a const in the class.
I should have thought of that! Thanks
Actually, those “images” are either embedded in “resource” directory of Xojo , or are drawn using API calls
(open the Xojo bundle and you might be surprised what you will see)
you can use base64 encoding as well and store them even in external file
how to assign the image from the string
Picture.FromData or write string to disk and then Picture.Open, or use one of the many MBS plugins.
[code] // Converts a base 64 encoded string to a picture by writing the (decoded) string
// to disk as a binary file and then reading it back in again as a picture.
dim bin as BinaryStream
dim f as FolderItem
dim d as New Date
dim p as Picture
// Save Picture Data in string form
f = getfolderitem("").Child(str(d.TotalSeconds) + " Temp Image")
bin = f.CreateBinaryFile("???")
if bin = nil then return nil
bin.Write DecodeBase64(StringToConvert) // String is in Base64 for XML prefs storage
// Open Picture
p = f.OpenAsPicture
if p = nil then return nil
[quote=367467:@Dave S]Actually, those “images” are either embedded in “resource” directory of Xojo , or are drawn using API calls
(open the Xojo bundle and you might be surprised what you will see)[/quote]
I have many applications without Resource directory, although all of them use images.
This is the Open even of my little “LED” class.
xxPicString are string constants in the class.
xxPic are private properties of the Picture class.
I wrote a little utility to open pictures from disk and convert to Base64-encoded strings, which I then copied and pasted into the constants in the IDE.
[code]dim m As MemoryBlock
m = DecodeBase64(OffPicString)
OffPic = Picture.FromData(m)
m = DecodeBase64(RedPicString)
RedPic = Picture.FromData(m)
m = DecodeBase64(YellowPicString)
YellowPic = Picture.FromData(m)
m = DecodeBase64(greenPicString)
GreenPic = Picture.FromData(m)
Here’s the picture-to-string bit in the utility:
mb = pic.GetData(Picture.FormatPNG)
s = mb
s = EncodeBase64(s)