Repository navigation
tkImage
Home › All Categories › tkControls › tkImage
Loads an image file once and draws it in any tkControls window.
tkImageFile holds one decoded image. You declare it, load it once, keep it as long as something shows it, and draw it with tkImage_Paint from a paint callback. The decoded pixels stay in memory; a texture is made the first time the image is drawn in a window and kept for that window, so the same image can appear in the main window, a popup menu and a tooltip. When a window goes, its textures go with it.
Formats are SDL_image's: .png, .bmp, .jpg / .jpeg, .gif, .ico / .cur, .tga, .qoi and more. Controls with an image slot load one for you from a path, for example tkToolbar_SetItemImage and tkIconPanel_SetImage.
#import "vendor/tkControls/tkImage"
using tkImage
using tkHost
using tkPainttkImage re-exports tkHost, and through it tkPaint, which holds TK_IMGFIT_*.
#import "vendor/tkControls/tkApp"
#import "vendor/tkControls/tkImage"
using tkApp
using tkHost
using tkPaint
using tkImage
dim shared as tkImageFile gLogo
sub Main_Paint( byval f as TK_FORM ptr, byval b as TK_PAINT ptr )
dim as TKRECT rc
tkRect_Set( rc, 0, 0, tkForm_Scale( f, 96 ), tkForm_Scale( f, 96 ) )
tkImage_Paint( b, @gLogo, @rc, TK_IMGFIT_ASPECT ) ' nothing when the load failed
end sub
tkApp_Init()
if gLogo.Load( "logo.png" ) = 0 then print "logo.png: " & *SDL_GetError()
dim as TK_FORM ptr f = tkApp_NewForm( "Logo", 320, 200 )
tkForm_OnPaint( f, @Main_Paint )
end tkApp_Run( f )-
Load( path ),LoadFromSurface( s )(copies anSDL_Surface; you keep yours) andLoadFromPixels( w, h, argb )(rows of&hAARRGGBB) return non-zero on success. A failed load clears the image held before. -
NaturalWidth/NaturalHeightgive the size in pixels;IsValidsays whether an image is held;Disposefrees it early. -
TK_IMGFIT_ASPECTfits the image inside the rect with its proportions kept,_STRETCHfills the rect,_CENTERdraws it at its natural size, centred and clipped. -
Surface()andTexture( renderer )hand out what the object owns: never destroy them.
| PsImage | tkImage |
|---|---|
PsImageFile |
tkImageFile |
PS_IMGFIT_* |
TK_IMGFIT_* (in tkPaint) |
buffer.PaintImage( img.Image( ), rc, fit ) |
tkImage_Paint( b, @img, @rc, fit ) |
Image( ) |
Surface( ), Texture( renderer )
|
LoadFromBitmap (HBITMAP), LoadFromIcon (HICON) |
LoadFromSurface, LoadFromPixels
|
- Decoding is SDL_image's, so the formats are SDL_image's rather than GDI+'s.
- One object draws in every window; there is nothing to reload per window or per scale.
The PsImage page remains the behaviour reference for everything not listed here.
Every public name the module declares, as the source declares it. Signatures are exact; type bodies keep their field comments and drop the rest.
type TKIMG_TEX
r as SDL_Renderer ptr
tex as SDL_Texture ptr
end type
type tkImageFile
pSurf as SDL_Surface ptr
cache(0 to 7) as TKIMG_TEX
pNextLive as tkImageFile ptr
pPrevLive as tkImageFile ptr
declare sub DropTextures()
declare constructor()
declare destructor()
declare function Load( byval path as ustring ) as long
declare function LoadFromSurface( byval s as SDL_Surface ptr ) as long
declare function LoadFromPixels( byval w as long, byval h as long, byval argb as ulong ptr ) as long
declare sub Dispose()
declare function IsValid() as long
declare function NaturalWidth() as long
declare function NaturalHeight() as long
declare function Surface() as SDL_Surface ptr
declare function Texture( byval r as SDL_Renderer ptr ) as SDL_Texture ptr
declare sub PurgeRenderer( byval r as SDL_Renderer ptr )
end typesub tkImage_Paint( byval p as TK_PAINT ptr, byval img as tkImageFile ptr, byval rc as TKRECT ptr, byval nFit as long = TK_IMGFIT_ASPECT )- tkControls
- tkApp, tkHost
- PsImage, the PsControls module
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Home
- What Is tiko-lang
- Quick Start
- Installing on macOS
- Debugging
- Feature Index
- Compatibility
- FAQ
- AI Cheatsheet
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Time Zones
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing