BlitzMax

BlitzMax

  • Downloads
  • Docs
  • API
  • Resources
  • About

›Pixmap

BlitzMax API

  • Introduction

BRL

    Audio

    • Introduction
    • TChannel
    • TSound

    AudioSample

    • Introduction
    • TAudioSample
    • TAudioSampleLoader

    Bank

    • Introduction
    • TBank

    BankStream

    • Introduction
    • TBankStream

    Base64

    • Introduction
    • TBase64

    Blitz

    • Introduction
    • TArrayBoundsException
    • TBlitzException
    • TNullFunctionException
    • TNullMethodException
    • TNullObjectException
    • TOutOfDataException
    • TRuntimeException
  • BRL.BMPLoader
  • Clipboard

    • Introduction
    • TClipboard
    • TClipboardOpts
    • TWin32ClipboardOpts
    • TX11ClipboardOpts
  • BRL.D3D7Max2D
  • BRL.D3D9Max2D
  • BRL.DirectSoundAudio
  • BRL.EndianStream
  • Event

    • Introduction
    • TEvent
  • BRL.EventQueue
  • BRL.FileSystem
  • BRL.FreeAudioAudio
  • BRL.GLGraphics
  • BRL.GLMax2D
  • BRL.GNet
  • BRL.Graphics
  • BRL.Hook
  • IO

    • Introduction
    • MaxIO
  • BRL.JPGLoader
  • BRL.KeyCodes
  • LinkedList

    • Introduction
    • TList
    • TListEnum
    • TLink

    Map

    • Introduction
    • TMap
    • TIntMap
    • TIntKey
    • TPtrMap
    • TPtrKey
    • TStringMap
  • BRL.Math
  • Matrix

    • Introduction
    • SMat2D
    • SMat2F
    • SMat2I
    • SMat3D
    • SMat3F
    • SMat3I
    • SMat4D
    • SMat4F
    • SMat4I

    Max2D

    • Introduction
    • TImage

    MaxLua

    • Introduction
    • TLuaClass
    • TLuaObject
  • BRL.OGGLoader
  • BRL.OpenALAudio
  • ObjectList

    • Introduction
    • TObjectList
    • TObjectListEnumerator
    • TObjectListReverseEnumerator

    Pixmap

    • Introduction
    • TPixmap
    • TPixmapLoader
  • BRL.PNGLoader
  • BRL.PolledInput
  • Quaternion

    • Introduction
    • SQuatD
    • SQuatF
    • SQuatI
  • BRL.RamStream
  • Random

    • Introduction
    • TRandom

    Reflection

    • Introduction
    • TTypeId
    • TMember
    • TConstant
    • TField
    • TGlobal
    • TFunction
    • TMethod
  • BRL.Retro
  • BRL.Socket
  • BRL.SocketStream
  • BRL.StandardIO
  • Stream

    • Introduction
    • TCStream
    • TIO
    • TStream
    • TStreamException
    • TStreamFactory
    • TStreamReadException
    • TStreamWrapper
    • TStreamWriteException

    StringBuilder

    • Introduction
    • TStringBuilder
    • TSplitBuffer
  • BRL.System
  • BRL.SystemDefault
  • BRL.TextStream
  • BRL.TGALoader
  • ThreadPool

    • Introduction
    • TRunnable
    • TThreadPoolExecutor

    Threads

    • Introduction
    • TThread
    • TThreadData
    • TMutex
    • TSemaphore
    • TCondVar

    Timer

    • Introduction
    • TChrono
  • BRL.TimerDefault
  • Vector

    • Introduction
    • SVec2D
    • SVec2F
    • SVec2I
    • SVec3D
    • SVec3F
    • SVec3I
    • SVec4D
    • SVec4F
    • SVec4I

    Volumes

    • Introduction
    • TVolume
  • BRL.WAVLoader

Text

    CSV

    • Introduction
    • TCsvParser
    • TCsvHeader
    • TCsvRow
    • TCsvOptions
    • SCsvColumn

    Format

    • Introduction
    • TFormatter

    Ini

    • Introduction
    • TIni
    • TIniProperty
    • TIniSection

    JConv

    • Introduction
    • TJConv
    • TJConvBuilder
    • TJConvSerializer

    Json

    • Introduction
    • TJSON
    • TJSONObject
    • TJSONString
    • TJSONInteger
    • TJSONReal
    • TJSONBool
    • TJSONArray
    • TJSONNull
    • TJSONError
    • TJSONNumber

    Regex

    • Introduction
    • TRegEx
    • TRegExMatch
    • TRegExOptions
    • TRegExException

    TOML

    • Introduction
    • ETomlNodeType
    • TToml
    • ITomlNode
    • STomlDate
    • STomlDateTime
    • STomlTime
    • TTomlArray
    • TTomlInteger
    • TTomlString
    • TTomlTable
    • TTomlBoolean

    Xml

    • Introduction
    • TxmlDoc
    • TxmlNode
    • TxmlAttribute

MaxGUI

  • MaxGUI.MaxGUI
  • MaxGUI.Drivers
  • MaxGUI.Localization
  • MaxGUI.ProxyGadgets
  • MaxGUI.CocoaMaxGUI
  • MaxGUI.Win32MaxGUIEx

PUB

  • Pub.FreeJoy
  • Pub.FreeProcess
  • Pub.Glad
  • Pub.Glew
  • Joystick

    • Introduction
    • TJoystickDriver
  • Pub.Lua
  • Pub.OpenAL
  • Pub.OpenGLES
  • Pub.xmmintrin
  • Pub.ZLib

Crypto

    Digest

    • Introduction
    • TMessageDigest
    • TDigestRegister
    • TNoSuchAlgorithmException

    Cipher

    • Introduction
    • TCipher
    • TCipherMode
    • Crypto.AESCipher
    • Crypto.AnubisCipher
    • Crypto.BlowfishCipher
    • Crypto.CamelliaCipher
    • Crypto.Cast5Cipher
    • Crypto.DESCipher
    • Crypto.IdeaCipher
    • Crypto.KasumiCipher
    • Crypto.KhazadCipher
    • Crypto.KSeedCipher
    • Crypto.NoekeonCipher
    • Crypto.SerpentCipher
    • Crypto.SkipjackCipher
    • Crypto.TwofishCipher
    • Crypto.XTeaCipher

    CBCMode

    • Introduction
    • TCBCCipherMode

    CFBMode

    • Introduction
    • TCFBCipherMode

    CTRMode

    • Introduction
    • TCTRCipherMode

    ECBMode

    • Introduction
    • TECBCipherMode

    F8Mode

    • Introduction
    • TF8CipherMode

    LRWMode

    • Introduction
    • TLRWCipherMode

    OFBMode

    • Introduction
    • TOFBCipherMode

    XTSMode

    • Introduction
    • TXTSCipherMode

    Blake2BDigest

    • Introduction
    • TBlake2B_512
    • TBlake2B_384
    • TBlake2B_256
    • TBlake2B_160

    CRC32

    • Introduction
    • TCRC32

    MD5Digest

    • Introduction
    • TMD5

    Ripemd320Digest

    • Introduction
    • TRipemd320

    Ripemd356Digest

    • Introduction
    • TRipemd256

    Ripemd160Digest

    • Introduction
    • TRipemd160

    Ripemd128Digest

    • Introduction
    • TRipemd128

    SHA1Digest

    • Introduction
    • TSHA1

    SHA256Digest

    • Introduction
    • TSHA256

    SHA512Digest

    • Introduction
    • TSHA512

    SHA3Digest

    • Introduction
    • TSHA3_512
    • TSHA3_384
    • TSHA3_256
    • TSHA3_224

    TigerDigest

    • Introduction
    • TTiger

    WhirlpoolDigest

    • Introduction
    • TWhirlpool

    Crypto

    • Introduction
    • TCryptoRandom
    • TCryptoSecretBox
    • TCryptoHash
    • TCryptoSign
    • TCryptoKeyExchange
    • TCryptoKey
    • TCryptoHashKey
    • TCryptoSecretBoxKey
    • TCryptoSignature
    • TCryptoExchangeKeyPair
    • TCryptoSessionKeyPair
    • TCryptoNPacket
    • TCryptoKK1Packet
    • TCryptoKK2Packet
    • TCryptoXX1Packet
    • TCryptoXX2Packet
    • TCryptoXX3Packet
    • TCryptoExchangeState
    • TCryptoPWHashMasterKey
    • TCryptoPWHashStoredKey
    • TCryptoPasswordHash

SDL

    SDL

    • Introduction
    • TSDLStream

    SDLSystem

    • Introduction
    • TSDLMultiGesture

    SDLVideo

    • Introduction
    • TSDLDisplay
    • TSDLDisplayMode
    • TSDLGLContext
    • TSDLWindow

    SDLRender

    • Introduction
    • TSDLRenderer
    • TSDLTexture

    SDLTimer

    • Introduction
    • TSDLTimer

    SDLHaptic

    • Introduction
    • TSDLHaptic
    • TSDLHapticCondition
    • TSDLHapticConstant
    • TSDLHapticCustom
    • TSDLHapticDirection
    • TSDLHapticEffect
    • TSDLHapticLeftRight
    • TSDLHapticPeriodic
    • TSDLHapticRamp

    SDLSensor

    • Introduction
    • TSDLSensor
  • SDL.SDLFreeAudio
  • SDL.GLSDLMax2D
  • SDL.GL2SDLMax2D
  • SDL.D3D9SDLMax2D
  • SDLVirtualJoystick

    • Introduction
    • TVirtualJoystick

Steam

    SteamSDK

    • Introduction
    • TSteamClient
    • TSteamUtils
    • TSteamUserStats
    • TSteamFriends
    • TSteamUGC
    • ISteamFriendsListener
    • ISteamUGCListener
    • ISteamUserStatsListener
    • ISteamUtilsListener
    • EItemPreviewType
    • EPersonaChange
    • EPersonaState
    • ERemoteStoragePublishedFileVisibility
    • EUGCMatchingUGCType
    • EUGCQuery
    • EUserRestriction
    • EUserUGCList
    • EWorkshopFileType
Edit

BRL.Pixmap

Pixmaps provide storage for rectangular regions of pixels.

You can create a new pixmap using the CreatePixmap command, or load a pixmap using LoadPixmap.

Pixmaps have 5 properties: width, height, a byte pointer to the pixmap's pixels, pitch and format.

You can retrieve a pointer to a pixmap's pixels using the PixmapPixelPtr command.

A pixmap's pitch refers to the number of bytes between one row of pixels in the pixmap and the next. To retrieve a pixmap's pitch, use the PixmapPitch command.

A pixmap's pixel format determines how the pixels within a pixmap are stored in memory. This must be taken into account if you want to access pixels directly via a pixmap's pixel pointer. You can retrieve the format of a pixmap using the PixmapFormat command, and convert pixmaps from one format to another using ConvertPixmap.

You can also use ResizePixmap to resize a pixmap and flip a pixmap horizontally or vertically with XFlipPixmap and YFlipPixmap.

Types

TypeDescription
TPixmapThe Pixmap type
TPixmapLoaderAbstract base type for pixmap loaders

Functions

Function CreatePixmap:TPixmap( width,height,format,align_bytes=4 )

Create a pixmap

format should be one of the following:

FormatDescription
PF_A88 bit alpha
PF_I88 bit intensity
PF_RGB88824 bit big endian RGB
PF_BGR88824 bit little endian RGB
PF_RGBA888832 bit big endian RGB with alpha
PF_BGRA888832 bit little endian RGB with alpha

Note that the newly created pixmap will contain random data. ClearPixels can be used to set all pixels to a known value prior to use.

Returns

A new pixmap object of the specified width and height


Function CreateStaticPixmap:TPixmap( pixels:Byte Ptr,width,height,pitch,format )

Create a pixmap with existing pixel data

The memory referenced by a static pixmap is not released when the pixmap is deleted.

See CreatePixmap for valid pixmap formats.

Returns

A new pixmap object that references an existing block of memory


Function CopyPixmap:TPixmap( pixmap:TPixmap )

Copy a pixmap

Returns

A new pixmap object

Example

SuperStrict

Graphics 640 , 480

Local pix:TPixmap=LoadPixmap(blitzmaxpath()+"\samples\hitoro\gfx\boing.png")
If pix = Null Then
    RuntimeError ("Error Loading Image")
End If


Local newPix:TPixmap=CopyPixmap(pix)

Repeat
    Cls
    DrawPixmap pix, 50, 50
    DrawPixmap newPix, MouseX(), MouseY()
    Flip
Until KeyHit(key_escape) Or AppTerminate()


Function ConvertPixmap:TPixmap( pixmap:TPixmap,format )

Convert pixel format of a pixmap

See CreatePixmap for valid pixmap formats.

Returns

A new pixmap object with the specified pixel format


Function PixmapWidth( pixmap:TPixmap )

Get pixmap width

Returns

The width, in pixels, of pixmap

Example

SuperStrict

Graphics 640,480
Local pix:TPixmap=LoadPixmap(blitzmaxpath()+"\samples\hitoro\gfx\boing.png")

If pix = Null Then
    RuntimeError ("Error Loading Image")
End If

Repeat
    Cls
    ' Display Information
    DrawText "Image Width:"+PixmapWidth(pix)+"  Image Height:"+PixmapHeight(pix),0,0 

    DrawPixmap pix,100,100
    Flip
Until KeyHit(key_escape) Or AppTerminate()


Function PixmapHeight( pixmap:TPixmap )

Get pixmap width

Returns

The height, in pixels, of pixmap

Example

SuperStrict

Graphics 640,480

Local pix:TPixmap = LoadPixmap(blitzmaxpath()+"\samples\hitoro\gfx\boing.png")

If pix = Null Then
    RuntimeError ("Error Loading Image")
End If

Repeat
    Cls
    
    ' Display Information
    DrawText "Image Width:"+PixmapWidth(pix)+"  Image Height:"+PixmapHeight(pix),0,0 

    DrawPixmap pix,100,100
    Flip
Until KeyHit(key_escape) Or AppTerminate()


Function PixmapPitch( pixmap:TPixmap )

Get pixmap pitch

Pitch refers to the difference, in bytes, between the start of one row of pixels and the start of the next row.

Returns

The pitch, in bytes, of pixmap


Function PixmapFormat( pixmap:TPixmap )

Get pixmap format

See CreatePixmap for supported formats.

Returns

The format of the pixels stored in pixmap


Function PixmapPixelPtr:Byte Ptr( pixmap:TPixmap,x=0,y=0 )

Get pixmap pixels

Returns

A byte pointer to the pixels stored in pixmap


Function PixmapWindow:TPixmap( pixmap:TPixmap,x,y,width,height )

Create a pixmap window

PixmapWindow creates a 'virtual' window into pixmap.

Returns

A new pixmap object


Function MaskPixmap:TPixmap( pixmap:TPixmap,mask_red,mask_green,mask_blue ) NoDebug

Mask a pixmap

MaskPixmap builds a new pixmap with alpha components set to '0' wherever the pixel colors in the original pixmap match mask_red, mask_green and mask_blue. mask_red, mask_green and mask_blue should be in the range 0 to 255.

Returns

A new pixmap object


Function XFlipPixmap:TPixmap( pixmap:TPixmap ) NoDebug

Flip a pixmap horizontally

Returns

A new pixmap object

Example

SuperStrict

Graphics 640,480

Local pix:TPixmap=LoadPixmap(blitzmaxpath()+"\samples\hitoro\gfx\boing.png")

If pix = Null Then
    RuntimeError ("Error Loading Image")
End If

Repeat
    Cls
    DrawText "Press Key X or Y to change Orientation" , 10 , 10
    
    ' Change pixmap orientation
    If KeyHit(KEY_X) Then
        pix = XFlipPixmap(pix)
    End If
    
    If KeyHit(KEY_Y) Then
        pix = YFlipPixmap(pix)
    End If
    
    DrawPixmap pix,50,50
    Flip
Until KeyHit(key_escape) Or AppTerminate()


Function YFlipPixmap:TPixmap( pixmap:TPixmap ) NoDebug

Flip a pixmap vertically

Returns

A new pixmap object

Example

SuperStrict

Graphics 640,480

Local pix:TPixmap=LoadPixmap(blitzmaxpath()+"\samples\hitoro\gfx\boing.png")

If pix = Null Then
    RuntimeError ("Error Loading Image")
End If

Repeat
    Cls
    DrawText "Press Key X or Y to change Orientation" , 10 , 10
    
    ' Change pixmap orientation
    If KeyHit(KEY_X) Then
        pix = XFlipPixmap(pix)
    End If
    
    If KeyHit(KEY_Y) Then
        pix = YFlipPixmap(pix)
    End If
    
    DrawPixmap pix,50,50
    Flip
Until KeyHit(key_escape) Or AppTerminate()


Function ResizePixmap:TPixmap( pixmap:TPixmap,width,height ) NoDebug

Resize a pixmap

Returns

A new pixmap object of the specified width and height

Example

SuperStrict

Graphics 640 , 480

Local pix:TPixmap=LoadPixmap(blitzmaxpath()+"\samples\hitoro\gfx\boing.png")

If pix = Null Then
    RuntimeError ("Error Loading Image")
End If

'Reduce Image by 50%
Local newPix:TPixmap=ResizePixmap(pix, Int(PixmapWidth(pix)*.5), Int(PixmapHeight(pix)*.5))

Repeat
    Cls
    DrawPixmap pix, 50, 50
    DrawPixmap newPix, MouseX() , MouseY()
    Flip
Until KeyHit(key_escape) Or AppTerminate()


Function LoadPixmap:TPixmap( url:Object )

Load a pixmap

Returns

A pixmap object

Example 1

SuperStrict

Graphics 640,480
Local player:TPixmap=LoadPixmap(blitzmaxpath()+"\samples\hitoro\gfx\boing.png")

If player = Null Then
    RuntimeError ("Error Loading Image")
End If

Repeat
    Cls
    DrawPixmap Player,10,10
    Flip
Until KeyHit(key_escape) Or AppTerminate()

Example 2

SuperStrict

Graphics 640 , 480

Local pix:TPixmap=LoadPixmap(blitzmaxpath()+"\samples\hitoro\gfx\boing.png")
'converts Pixmap to Image
'note alpha transparency
Local image:TImage=LoadImage(pix)

Repeat
    Cls
    DrawPixmap pix, 50, 50
    DrawImage image, MouseX(), MouseY()
    Flip
Until KeyHit(key_escape) Or AppTerminate()


Function ReadPixel( pixmap:TPixmap,x,y )

Read a pixel from a pixmap

The returned 32 bit value contains the following components:

bits 24-31pixel alpha
bits 16-23pixel red
bits 8-15pixel green
bits 0-7pixel blue

Returns

A 32 bit pixel value


Function WritePixel( pixmap:TPixmap,x,y,argb )

Write a pixel to a pixmap

The 32 bit argb value contains the following components:

bits 24-31pixel alpha
bits 16-23pixel red
bits 8-15pixel green
bits 0-7pixel blue


Function ClearPixels( pixmap:TPixmap,argb=0 )

Clear a pixmap

Sets all pixels in a pixmap to a 32 bit pixel value.

The 32 bit argb value contains the following components:

bits 24-31pixel alpha
bits 16-23pixel red
bits 8-15pixel green
bits 0-7pixel blue

Example

SuperStrict

Graphics 800 , 600

Local mypix:TPixmap = LoadPixmap(BlitzMaxPath()+"/samples/hitoro/gfx/boing.png")
If mypix = Null Then
    RuntimeError ("Error Loading Image")
End If

DrawPixmap mypix, 0, 0

ClearPixels(mypix, $FFFFFF)
 

DrawPixmap mypix, 300, 0

Flip

WaitKey


← TObjectListReverseEnumeratorTPixmap →
  • Types
  • Functions
    • Function CreatePixmap:TPixmap( width,height,format,align_bytes=4 )
    • Function CreateStaticPixmap:TPixmap( pixels:Byte Ptr,width,height,pitch,format )
    • Function CopyPixmap:TPixmap( pixmap:TPixmap )
    • Function ConvertPixmap:TPixmap( pixmap:TPixmap,format )
    • Function PixmapWidth( pixmap:TPixmap )
    • Function PixmapHeight( pixmap:TPixmap )
    • Function PixmapPitch( pixmap:TPixmap )
    • Function PixmapFormat( pixmap:TPixmap )
    • Function PixmapPixelPtr:Byte Ptr( pixmap:TPixmap,x=0,y=0 )
    • Function PixmapWindow:TPixmap( pixmap:TPixmap,x,y,width,height )
    • Function MaskPixmap:TPixmap( pixmap:TPixmap,mask_red,mask_green,mask_blue ) NoDebug
    • Function XFlipPixmap:TPixmap( pixmap:TPixmap ) NoDebug
    • Function YFlipPixmap:TPixmap( pixmap:TPixmap ) NoDebug
    • Function ResizePixmap:TPixmap( pixmap:TPixmap,width,height ) NoDebug
    • Function LoadPixmap:TPixmap( url:Object )
    • Function ReadPixel( pixmap:TPixmap,x,y )
    • Function WritePixel( pixmap:TPixmap,x,y,argb )
    • Function ClearPixels( pixmap:TPixmap,argb=0 )
BlitzMax
Docs
Getting StartedDownloadsAbout
Community
ResourcesSyntaxBomb Forums
More
GitHubStarChat on Discord
Copyright © 2023 Bruce A Henderson