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
Type | Description |
---|---|
TPixmap | The Pixmap type |
TPixmapLoader | Abstract 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:
Format | Description |
PF_A8 | 8 bit alpha |
PF_I8 | 8 bit intensity |
PF_RGB888 | 24 bit big endian RGB |
PF_BGR888 | 24 bit little endian RGB |
PF_RGBA8888 | 32 bit big endian RGB with alpha |
PF_BGRA8888 | 32 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-31 | pixel alpha |
bits 16-23 | pixel red |
bits 8-15 | pixel green |
bits 0-7 | pixel 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-31 | pixel alpha |
bits 16-23 | pixel red |
bits 8-15 | pixel green |
bits 0-7 | pixel 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-31 | pixel alpha |
bits 16-23 | pixel red |
bits 8-15 | pixel green |
bits 0-7 | pixel 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