Futurebasic/programming/drawing
Getting an Image on the Screen (Depreciated)
[edit | edit source]To get an image on the screen (using an older depreciated method), you have to include the image file in your project directory, and include the Core Graphics toolbox headers in your project. there is also a function the create a CG imageRef from a jpg or png file.
include resources "pBoard.png" include "Tlbx CoreGraphics.incl"
// Create a CGImageRef from a jpg or png image [KenS] local fn createCGImageRef( fileName as CFStringRef ) as CGImageRef
dim as CFURLRef url dim as CGImageRef imageRef : imageRef = 0 dim as CGDataProviderRef dataProvider
url = fn CFBundleCopyResourceURL( fn CFBundleGetMainBundle(), filename, 0, 0 ) long if ( url )
dataProvider = fn CGDataProviderCreateWithURL( url ) long if ( dataProvider )
select
case fn CFStringHasSuffix( fileName, fn CFSTR( ".jpg" ) ) imageRef = fn CGImageCreateWithJPEGDataProvider( dataProvider, NULL, _false, _kCGRenderingIntentDefault )
case fn CFStringHasSuffix( fileName, fn CFSTR( ".png" ) ) imageRef = fn CGImageCreateWithPNGDataProvider( dataProvider, NULL, _false, _kCGRenderingIntentDefault )
end select fn CGDataProviderRelease( dataProvider ) end if CFRelease( url ) end if
end fn = imageRef
Once you have the above function and includes in your project, you can add an image to a window — and it takes the form of a button, whose contents we set with the image pointed to by the CG imageRef, like so:
// DISPLAY BACKGROUND IMAGE dim as rect r dim as ControlButtonContentInfo content SetRect( @r, 20, 20, 532, 532 ) appearance button 99, , , "", @r , _kControlImageWellProc content.contentType = _kControlContentCGImageRef content.u.imageRef = fn createCGImageRef( @"pBoard.png" ) fn SetButtonData( 99, _kControlImageWellPart, _kControlImageWellContentTag, SizeOf( content ), content )