[futurebasic] re: Incorporating images using FBtoC

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : April 2013 : Group Archive : Group : All Groups

From: Ken Shmidheiser <kshmidheiser@...>
Date: Mon, 29 Apr 2013 23:14:06 -0400
My belated contribution as a single function.

Ken


include "Tlbx MoreFilesX.incl"

include resources "test.jpg"

local fn ResourceImageToPICTHandle( imageName as CFStringRef, imageRect as ^rect ) as handle
'~'1
dim as GraphicsImportComponent gi
dim as ComponentResult         result
dim as PicHandle               pictH : pictH = NULL
dim as CFURLRef                url
dim as FSRef                   fsRef
dim as FSSpec                  fsSpec
dim as OSErr                   err
dim as Boolean                 success

url = fn CFBundleCopyResourceURL( fn CFBundleGetMainBundle(), imageName, 0, 0 )
long if ( url )
success = fn CFURLGetFSRef( url, @fsRef )
CFRelease( url )
long if ( success )
err = fn FSGetCatalogInfo( @fsRef, _kFSCatInfoNone, NULL, NULL, #fsSpec, NULL )
long if ( err == _noErr )
err = fn GetGraphicsImporterForFile( fsSpec, gi )
long if ( err == _noErr )
result = fn GraphicsImportGetAsPicture( gi, pictH )
result = fn GraphicsImportGetBoundsRect( gi, #imageRect )
err = fn CloseComponent( gi )
end if
end if
end if
end if
end fn = (handle)pictH     // User must dispose

dim as handle pictH
dim as rect   r

pictH = fn ResourceImageToPICTHandle( @"test.jpg", @r )
window 1, "Show Image", @r
picture ( r.top, r.left ) - ( r.right, r.bottom ), pictH
fn DisposeH( pictH )

RunApplicationEventLoop()