« 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