Repository navigation
Imageconvertrow
Paul Squires edited this page Oct 19, 2026
·
2 revisions
Home › 2D Drawing Functions › ImageConvertRow
Copies a row of pixels to another buffer, converting its colour depth.
Declare Sub ImageConvertRow ( ByVal src As Any Ptr, ByVal src_bpp As Long, ByVal dst As Any Ptr, ByVal dst_bpp As Long, ByVal width As Long, ByVal isrgb As Long = 1 )srcsrc_bppdstdst_bppwidthisrgb
Copies the row of an image from one memory location to another, converting the color information in each pixel to match the destination image.
ImageConvertRow( src, src_bpp, dst, dst_bpp, width [, isrgb ] )
- Not available in the -lang qb dialect unless referenced with the alias
__ImageConvertRow.
- New to FreeBASIC
#include "fbgfx.bi"
#if __FB_LANG__ = "fb"
Using FB
#endif
Const As Long w = 64, h = 64
Dim As IMAGE Ptr img8, img32
Dim As Integer x, y
'' create a 32-bit image, size w*h:
ScreenRes 1, 1, 32, , GFX_NULL
img32 = ImageCreate(w, h)
If img32 = 0 Then Print "Imagecreate failed on img32!": Sleep: End
'' create an 8-bit image, size w*h:
ScreenRes 1, 1, 8, , GFX_NULL
img8 = ImageCreate(w, h)
If img8 = 0 Then Print "Imagecreate failed on img8!": Sleep: End
'' fill 8-bit image with a pattern
For y = 0 To h - 1
For x = 0 To w - 1
PSet img8, (x, y), 56 + (x + y) Mod 24
Next x
Next y
'' open a graphics window in 8-bit mode, and PUT the image into it:
ScreenRes 320, 200, 8
WindowTitle "8-bit color mode"
Put (10, 10), img8
Sleep
'' copy the image data into a 32-bit image
Dim As Byte Ptr p8, p32
Dim As Long pitch8, pitch32
#ifndef ImageInfo '' older versions of FB don't have the ImageInfo feature
#define GETPITCH(img_) IIf(img_->Type=PUT_HEADER_NEW,img_->pitch,img_->old.width*img_->old.bpp)
#define GETP(img_) CPtr(Byte Ptr,img_)+IIf(img_->Type=PUT_HEADER_NEW,SizeOf(PUT_HEADER),SizeOf(_OLD_HEADER))
pitch8 = GETPITCH(img8): p8 = GETP(img8)
pitch32 = GETPITCH(img32): p32 = GETP(img32)
#else
ImageInfo( img8, , , , pitch8, p8 )
ImageInfo( img32, , , , pitch32, p32 )
#endif
For y = 0 To h - 1
ImageConvertRow(@p8 [ y * pitch8 ], 8, _
@p32[ y * pitch32], 32, _
w)
Next y
'' open a graphics window in 32-bit mode and PUT the image into it:
ScreenRes 320, 200, 32
WindowTitle "32-bit color mode"
Put (10, 10), img32
Sleep
'' free the images from memory:
ImageDestroy img8
ImageDestroy img32Category: 2D Drawing Functions
Kind: sub
Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.
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