[futurebasic] Displaying a picture from the web

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : November 2011 : Group Archive : Group : All Groups

From: Ken Shmidheiser <kshmidheiser@...>
Date: Thu, 24 Nov 2011 13:52:59 -0500
Rich asked:

> Is there any way to make this work without requiring a compositing window?
> The _kWindowCompositingAttribute causes problems with my app.


Rich,

As I  earlier suggested, use an ImageWell as in the simple demo below which works
in a plain old FB window sans compositing.

If you insist on using a PICT, I suggest you download the CGImage as shown here,
and the convert the CGImage to a PICT (actually a PicHandle but you can cast it as
needed) to load into your Picture Button.

Here's some C code you could convert FB to do the job:

http://forums.supercard.us/viewtopic.php?f=9&t=1354

Just remember that PICTs are seriously antiquated.

Ken

/*

Load Internet Image into ImageWell

Ken Shmidheiser
Nov. 24, 2011

*/

include "Tlbx ControlDefinitions.incl"
include "Tlbx CoreGraphics.incl

_CGlmageRefImageWell = 1

// Plain ole FB window for Rich
local fn BuildWindow
'~'1
dim as Rect            r

SetRect( r, 0, 0, 820, 620 )
appearance window -1, "", @r, _kDocumentWindowClass, _kWindowCloseBoxAttribute

InsetRect( r, 10, 10 )
appearance button _CGlmageRefImageWell, _activeBtn,,0,1,,@r,_kControlImageWellProc
end fn

local fn SetCGImageRefIntoImageWell( whichWell as ControlRef, whichImage as CGImageRef ) as OSErr
'~'1
dim as OSStatus                   err
dim as ControlButtonContentInfo @ contentInfo

contentInfo.contentType = _kControlContentCGImageRef
contentInfo.u.imageRef = whichImage
err = fn SetImageWellContentInfo( whichWell, @contentInfo )
Draw1Control( whichWell )
end fn = err

local fn CGImageCreateWithURL( string as CFStringRef ) as CGImageRef
'~'1
dim as CFStringRef       urlString
dim as CFURLRef          url
dim as CGImageRef        image : image = NULL
dim as CGImageSourceRef  source

urlString = fn CFURLCreateStringByAddingPercentEscapes( _kCFAllocatorDefault, string, 0, 0, _kCFStringEncodingUTF8 )
if ( urlString )
url = fn CFURLCreateWithString( _kCFAllocatorDefault, string, #0 )
CFRelease( urlString )
if ( url )
source = fn CGImageSourceCreateWithURL( url, #0 )
CFRelease( url )
if ( source )
image = fn CGImageSourceCreateImageAtIndex( source, 0, 0 )
CFRelease( source )
end if
end if
end if
end fn = image     // User must release

fn BuildWindow

dim as CGImageRef  image
dim as ControlRef  imageWell

image = fn CGImageCreateWithURL( @"http://upload.wikimedia.org/wikipedia/commons/1/1b/Aganisia_cyanea_Orchi_03.jpg" )
if ( image )
fn SetCGImageRefIntoImageWell( Button&( _CGlmageRefImageWell ), image )
CGImageRelease( image )
end if

window 1

RunApplicationEventLoop()