« Sending files from Fi… | Home | MBS Xojo / Real Studi… »

Tip of the day: Quickly query image size

If you just need the size of an image on Mac OS X in your Xojo app, well using CGImageSource can be much faster than opening the image for that. By using Picture.Open you load the whole image in memory which can take a few milliseconds. Loading just the file header with metadata can be much faster. So the following code uses CGImageSourceMBS class to open the image and read the properties of the first image:

// open an image file dim path as string = "/Library/Desktop Pictures/Galaxy.jpg" dim f as FolderItem = GetFolderItem(path, FolderItem.PathTypeNative) Dim c As New CGImageSourceMBS(f) // properties for first image dim p as Dictionary = c.PropertiesAtIndex(0) dim w as integer = p.Value(c.kCGImagePropertyPixelWidth) dim h as integer = p.Value(c.kCGImagePropertyPixelHeight)
18 10 14 - 13:15
two comments

is there an equivalent for windows os??
Trisha Duke (Email) - 25 10 14 - 14:39

Sorry, no idea.
Christian Schmitz (URL) - 25 10 14 - 14:41

Remember personal info?

Emoticons / Textile

Hide email:

Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.