For an eBook or printed book on using the API with Liberty BASIC, see: APIs for Liberty BASIC
Parallelogram Blitting
The PlgBlt function performs a bit-block transfer of the bits of color data from the specified rectangle in the source device context to the specified parallelogram in the destination device context.
Bitmaps are rectangular images. PlgBlt displays a copy of the bitmap skewed into the specified parallelogram shape.
PlgBlt
The parameters of the PlgBlt function are as follows.
calldll#gdi32,"PlgBlt",_
hdcDest hdcDest asulong,_ 'source device context
lpPoint asstruct,_ 'array of points
memdc asulong,_ 'destination device context
nXSrc aslong,_ 'upper left x-coord of source
nYSrc aslong,_ 'upper left y-coord of source
nWidth aslong,_ 'width of source
nHeight aslong,_ 'height of source
hbmMask asulong,_ 'mask bmp handle, null if not used
xMask aslong,_ 'ulx mask
yMask aslong,_ 'uly mask
re aslong'nonzero=success
hdcDest: A handle to the destination device context.
lpPoint: A pointer to an array of three points in logical space that identify three corners of the destination parallelogram. The upper-left corner of the source rectangle is mapped to the first point in this array, the upper-right corner to the second point in this array, and the lower-left corner to the third point. The lower-right corner of the source rectangle is mapped to the implicit fourth point in the parallelogram.
hdcSrc: A handle to the source device context.
nXSrc: The x-coordinate, in logical units, of the upper-left corner of the source rectangle.
nYSrc: The y-coordinate, in logical units, of the upper-left corner of the source rectangle.
nWidth: The width, in logical units, of the source rectangle.
nHeight: The height, in logical units, of the source rectangle.
hbmMask: A handle to an optional monochrome bitmap that is used to mask the colors of the source rectangle.
xMask: The x-coordinate, in logical units, of the upper-left corner of the monochrome bitmap.
yMask: The y-coordinate, in logical units, of the upper-left corner of the monochrome bitmap.
Return value: If the function succeeds, the return value is nonzero.
Not all devices support the PlgBlt function. If the source and destination device contexts represent incompatible devices, PlgBlt returns an error. When used in a multiple monitor system, both hdcSrc and hdcDest must refer to the same device or the function will fail.
Demo One
The example below allows the user to open a bitmap file. It is then displayed in a graphicbox in a specified parallelogram shape. The simple deom does not include a mask.
A picture of George Washington is opened in the demo program. The result looks like this:
filedialog"Open","*.bmp",bmp$
if bmp$=""thenendloadbmp"image",bmp$
hImage=hbmp("image")struct BITMAP,_
bmType aslong,_
bmWidth Aslong,_
bmHeight Aslong,_
bmWidthBytes Aslong,_
bmPlanes asword,_
bmBitsPixel asword,_
bmBits asLong
length=len(BITMAP.struct)calldll#gdi32,"GetObjectA", hImage asulong,_
length aslong,BITMAP asstruct,_
results aslong
bmpWidth=BITMAP.bmWidth.struct
bmpHeight=BITMAP.bmHeight.structnomainwin
winWide=700:winHigh=500WindowWidth=winWide+50:WindowHeight=winHigh+50UpperLeftX=1:UpperLeftY=1graphicbox#1.g,0,0,winWide,winHigh
open"Parallelogram Blt"forwindowas#1#1"trapclose [quit]"#1.g "down;fill lightgray"
h=hwnd(#1.g)'graphicbox handle'get device context for window:calldll#user32,"GetDC",_
h asulong,_ 'graphicbox handle
hdc asulong'returns handle to device contextCallDLL#gdi32,"CreateCompatibleDC",_
hdc asuLong,_
memdc asuLongCallDLL#gdi32,"SelectObject",_
memdc asuLong,_
hImage asuLong,_
oldObject asuLongSTRUCT lpPoint,_
x1 aslong,_ 'ulx
y1 aslong,_ 'uly
x2 aslong,_ 'urx
y2 aslong,_ 'ury
x3 aslong,_ 'llx
y3 aslong'lly'The STRUCT must be filled before it can be used in an api call:
lpPoint.x1.struct=int(winWide/2)
lpPoint.y1.struct=0
lpPoint.x2.struct= winWide
lpPoint.y2.struct=int(winHigh/2)
lpPoint.x3.struct=0
lpPoint.y3.struct=int(winHigh/2)calldll#gdi32,"PlgBlt",_
hdc asulong,_ 'device context of graphicbox
lpPoint asstruct,_ 'array of points
memdc asulong,_ 'memory DC0aslong,_ 'ulx source0aslong,_ 'uly source
bmpWidth aslong,_ 'width source
bmpHeight aslong,_ 'height source0asulong,_ 'mask bmp handle, null = not used0aslong,_ 'ulx mask0aslong,_ 'uly mask
re aslong'nonzero=success'method to flush GDI graphics:'#1.g "getbmp pix 0 0 ";winWide;" ";winHigh'#1.g "drawbmp pix 0 0;flush"wait[quit]calldll#user32,"ReleaseDC",_
h asulong,_ 'window handle
hdc asulong,_ 'device context
ret aslongCallDLL#gdi32,"DeleteDC",memdc asuLong, r AsBooleanclose#1:end
Masking
If the given bitmask handle identifies a valid monochrome bitmap, the function uses this bitmap to mask the bits of color data from the source rectangle. If the mask rectangle is smaller than the source and destination rectangles, the function replicates the mask pattern.
If the bitmask exists, a value of one in the mask indicates that the source pixel color should be copied to the destination. A value of zero in the mask indicates that the destination pixel color is not to be changed.
Liberty BASIC's loadbmp statement does not load a monochrome bitmap. Instead, we use the API function LoadImageA. The flags for loading should include the flag for loading from a file and the flag for a monochrome bitmap. Be sure to use a mask bitmap that contains only white and black. The LoadImageA function looks like this:
imagePath$=DefaultDir$;"\plg_mask.bmp"
flags = _LR_MONOCHROME or _LR_LOADFROMFILE
calldll#user32,"LoadImageA",_
0asulong,_ 'instance - use 0 for image from file
imagePath$ asptr,_ 'path and filename of image
_IMAGE_BITMAP aslong,_ 'type of image
bmpWidth aslong,_ 'desired width
bmpHeight aslong,_ 'desired height
flags aslong,_ 'load flags
hMask asUlong'handle of loaded image
The mask used looks like this:
Masking Demo
The code below looks like this when run:
filedialog"Open","*.bmp",bmp$
if bmp$=""thenendloadbmp"image",bmp$
hImage=hbmp("image")struct BITMAP,_
bmType aslong,_
bmWidth Aslong,_
bmHeight Aslong,_
bmWidthBytes Aslong,_
bmPlanes asword,_
bmBitsPixel asword,_
bmBits asLong
length=len(BITMAP.struct)calldll#gdi32,"GetObjectA", hImage asulong,_
length aslong,BITMAP asstruct,_
results aslong
bmpWidth=BITMAP.bmWidth.struct
bmpHeight=BITMAP.bmHeight.struct'need monochrome bmp'create black and white bmp and save to disk'use LoadImageA with monochrome flag set' to assure handle to monochrome bmp
imagePath$=DefaultDir$;"\plg_mask.bmp"
flags = _LR_MONOCHROME or _LR_LOADFROMFILE
calldll#user32,"LoadImageA",_
0asulong,_ 'instance - use 0 for image from file
imagePath$ asptr,_ 'path and filename of image
_IMAGE_BITMAP aslong,_ 'type of image
bmpWidth aslong,_ 'desired width
bmpHeight aslong,_ 'desired height
flags aslong,_ 'load flags
hMask asUlong'handle of loaded imagenomainwin
winWide=700:winHigh=500WindowWidth=winWide+50:WindowHeight=winHigh+50UpperLeftX=1:UpperLeftY=1graphicbox#1.g,0,0,winWide,winHigh
open"Masked Parallelogram Blt"forwindowas#1#1"trapclose [quit]"#1.g "down;fill lightgray"
h=hwnd(#1.g)'graphicbox handle'get device context for window:calldll#user32,"GetDC",_
h asulong,_ 'graphicbox handle
hdc asulong'returns handle to device contextCallDLL#gdi32,"CreateCompatibleDC",_
hdc asuLong,_
memdc asuLongCallDLL#gdi32,"SelectObject",_
memdc asuLong,_
hImage asuLong,_
oldObject asuLongSTRUCT lpPoint,_
x1 aslong,_ 'ulx
y1 aslong,_ 'uly
x2 aslong,_ 'urx
y2 aslong,_ 'ury
x3 aslong,_ 'llx
y3 aslong'lly'The STRUCT must be filled before it can be used in an api call:
lpPoint.x1.struct=int(winWide/2)
lpPoint.y1.struct=0
lpPoint.x2.struct= winWide
lpPoint.y2.struct=int(winHigh/2)
lpPoint.x3.struct=0
lpPoint.y3.struct=int(winHigh/2)calldll#gdi32,"PlgBlt",_
hdc asulong,_ 'device context of graphicbox
lpPoint asstruct,_ 'array of points
memdc asulong,_ 'memory DC0aslong,_ 'ulx source0aslong,_ 'uly source
bmpWidth aslong,_ 'width source
bmpHeight aslong,_ 'height source
hMask asulong,_ 'mask monochrome bmp handle0aslong,_ 'ulx mask0aslong,_ 'uly mask
re aslong'nonzero=success'method to flush GDI graphics:'#1.g "getbmp pix 0 0 ";winWide;" ";winHigh'#1.g "drawbmp pix 0 0;flush"wait[quit]calldll#user32,"ReleaseDC",_
h asulong,_ 'window handle
hdc asulong,_ 'device context
ret aslongCallDLL#gdi32,"DeleteDC",memdc asuLong, r AsBooleanclose#1:end
-
Parallelogram Blitting | PlgBlt | Demo One | Masking | Masking Demo
Some text below is copied from the Microsoft Developers Network Library.
For an eBook or printed book on using the API with Liberty BASIC, see:
APIs for Liberty BASIC
Parallelogram Blitting
The PlgBlt function performs a bit-block transfer of the bits of color data from the specified rectangle in the source device context to the specified parallelogram in the destination device context.Bitmaps are rectangular images. PlgBlt displays a copy of the bitmap skewed into the specified parallelogram shape.
PlgBlt
The parameters of the PlgBlt function are as follows.hdcDest: A handle to the destination device context.
lpPoint: A pointer to an array of three points in logical space that identify three corners of the destination parallelogram. The upper-left corner of the source rectangle is mapped to the first point in this array, the upper-right corner to the second point in this array, and the lower-left corner to the third point. The lower-right corner of the source rectangle is mapped to the implicit fourth point in the parallelogram.
hdcSrc: A handle to the source device context.
nXSrc: The x-coordinate, in logical units, of the upper-left corner of the source rectangle.
nYSrc: The y-coordinate, in logical units, of the upper-left corner of the source rectangle.
nWidth: The width, in logical units, of the source rectangle.
nHeight: The height, in logical units, of the source rectangle.
hbmMask: A handle to an optional monochrome bitmap that is used to mask the colors of the source rectangle.
xMask: The x-coordinate, in logical units, of the upper-left corner of the monochrome bitmap.
yMask: The y-coordinate, in logical units, of the upper-left corner of the monochrome bitmap.
Return value: If the function succeeds, the return value is nonzero.
Not all devices support the PlgBlt function. If the source and destination device contexts represent incompatible devices, PlgBlt returns an error. When used in a multiple monitor system, both hdcSrc and hdcDest must refer to the same device or the function will fail.
Demo One
The example below allows the user to open a bitmap file. It is then displayed in a graphicbox in a specified parallelogram shape. The simple deom does not include a mask.A picture of George Washington is opened in the demo program. The result looks like this:
Masking
If the given bitmask handle identifies a valid monochrome bitmap, the function uses this bitmap to mask the bits of color data from the source rectangle. If the mask rectangle is smaller than the source and destination rectangles, the function replicates the mask pattern.If the bitmask exists, a value of one in the mask indicates that the source pixel color should be copied to the destination. A value of zero in the mask indicates that the destination pixel color is not to be changed.
Liberty BASIC's loadbmp statement does not load a monochrome bitmap. Instead, we use the API function LoadImageA. The flags for loading should include the flag for loading from a file and the flag for a monochrome bitmap. Be sure to use a mask bitmap that contains only white and black. The LoadImageA function looks like this:
The mask used looks like this:
Masking Demo
The code below looks like this when run:GDI Tutorials Home