Rapid-Q Documentation by William Yu (c)1999, appended by D.Glodt (c)2000-2004, John Kelly Appendix A: QBITMAPEX

QBITMAPEX Component

INCLUDED IN RAPIDQ2.INC
QBitmapEx is just like a QBITMAP except it supports other goodies like Clipboard paste and copy, alphablending, 8-bit greyscale bmp, loadi/save of other graphic formats (JPG, PNG, GIF, TIF, etc.).
Some components use GDI+ and therefore will not run under Windows 95/98
  See limitations.

QBitmapEx Properties
FieldTypeR/WDefaultSupport





bpp
bytes per pixel of current format
R
0

PenSize Long RW 1 W

Pen size for draw  line,rectangle and circle


PenStyle Long RW PS_SOLID_BMP W

Pen style , the others values are:
PS_SOLID_BMP=0
PS_DASH_BMP=1
PS_DOT_BMP=2
PS_DASHDOT_BMP=3
PS_DASHDOTDOT_BMP=4
PS_NULL_BMP=5
PS_INSIDEFRAME_BMP=6



GDIplusImage
Pointer to a GDI+ image class to aid GDI+ calling
R


UseGDIplus
If True, starts GDI+, if false shuts down GDI+
RW
False
W


QBitmapEx Methods
MethodTypeDescriptionParams

AlphaBlend
SUB(Dest AS QBITMAP, Source AS QBITMAP, PercentBlend AS SINGLE) Blend together two bitmaps 
    (Win98 or higher)
3

PercentBlend is from 0.0 to 1.0.
 If PercentBlend = -1 Then alphaBlending is determined by the Alpha values in Source Bitmap and Pixelformat must be pf32bit (32 bpp). The
output Bitmap will be replaced by the new alpha-blended bitmap. If the sizes of the two bitmaps are not equal the smaller will be stretched to equal the larger one
CreateGDIplusImage
SUB()
Create a GDI+ image class for GDI+ drawing. Value is stored in QBitmapEx.GDIplusImage 0
CopyFromGDIplus SUB()
Copy GDI+ image to QBitmap

CopyToGDIplus SUB()
Copy the QBitmap image to a GDI+ image
0
DestroyGDIplusImage SUB ()
Destroys a GDI+ image class if created
0
GDIStatus FUNCTION (Status&) AS STRING
Return GDI+ error return string
1
CopyToClipboard SUB Copy image to clipboard 0
PasteFromClipboard SUB(x%,y%) Paste the image of clipboard 2
GetWidthClipboard FUNCTION as INTEGER Return the image width  of clipboard 0
GetHeightClipboard FUNCTION as INTEGER Return the image height of clipboard 0
CanPaste FUNCTON as BOOLEAN Return true if image présent in the clipboard 0
CircleFilled SUB(x1%,y1%,x2%,y2%,c%,Fill%) Draw a circle filled 6
DrawIco SUB(left%,top%,width%,height%,handle%) Draw an icon 3
  If the width and height parameters  are  0,the icon will show with his dimensions by défault.  
FillSurface SUB(x%,y%,c%) Fill the surface pointed by the color of pixel x,y 3
Flip SUB(x%,y%,width%,height%) Make a miror y 4
GreyScale
SUB()
Converts to 8-bit greyscale

InvertColor SUB(x%,y%,width%,height%) Invert color 4
LoadFromFile
FUNCTION( Filename$)
supports loading BMP, JPG, PNG, TIF, GIF

LoadOtherImageSUB(FileName$,Progress&,Language$)Depreciated

Mirror SUB(x%,y%,width%,height%) Make a miror x 4
PointerLONGR
 Returns the memory location of the pixel data:
myBMP.loadFromFile "\RapidQ\Test.bmp" 
Showmessage STR$(myBMP.Pointer)
RectangleFilled SUB(x1%,y1%,x2%,y2%,c%,Fill%) Draw a rectangle filled 6
RotateFast
SUB (x%, y%, Angle AS SINGLE)
Faster rotation using GDI
3
RoundRectFilled SUB(x1%,y1%,x2%,y2%,x3%,y3%,c%,Fill%) Draw a round rectangle filled 8
SaveAsJpg SUB(FileName$, Quality&) Depreciated

SaveToFile FUNCTION(FileName$,  [Quality&] ) Save image in jpg, png, tif, or gif format. The optional Quality parameter is jpg lossless quality. 1 = low, 100 = high quality 2

"$INCLUDE "rapidq2.inc"
DEFINT i
DIM myBmp AS QBITMAPEX
myBmp.width = 256
myBmp.Height = 256
myBmp.GreyScale  '8bit greyscale
FOR i = 0 to 255
  myBmp.Line(i, 0, i, 256,  RGB(i,i,i)) ' note need full rgb
NEXT i
myBMP.SaveToFile ("greyscale.jpg", 100)
myBMP.SaveToFile ("test.png")
SetPalette
SUB (lpPalArray&)

QBitmapEx.PixelFormat = pf8bit
'make our accurate greyscale palette
DEFINT i = 0, c = 0
DIM RGBPal(1023) AS BYTE   'RGBQUAD * 0-255 = 1024
MEMSET(VARPTR(RGBPal(0)), 0, 1024)
DO
    RGBPal(i) = c       'blue
    RGBPal(i+1) = c     'green
    RGBPal(i+2) = c     'red
    c++
    INC(i, 4)           'skip A
LOOP UNTIL (i > 1023)
QBitmapEx.SetPalette(VARPTR(RGBPal(0)))
QBitmapEx Example

$INCLUDE "RapidQ2.inc"
DIM myBmp AS QBITMAPEX
myBmp.width = 256
myBmp.Height = 256
myBmp.GreyScale
FOR i = 0 to 255
myBmp.Line(i, 0, i, 256, RGB(i,i,i)) ' note need full rgb
NEXT i
myBMP.FillSurface(255, 255, 0)
myBMP.SaveToFile ("greyscale.jpg", 100)

QBitmapEx Example 2
$INCLUDE "rapidQ2.inc"
DECLARE SUB LoadImages
DIM TmpBMP AS QBITMAPex
DIM Src1 AS QBITMAPex 'source 1 for bitmap
DIM Src2 AS QBITMAPex 'source 2 for bmp blending
DIM fDialog as QFILEDIALOG

CREATE form as QFORM
width = Screen.Width
height = Screen.Height - 28
OnClick = LoadImages

create canvas as QCanvas
Top = 24
width = Form.ClientWidth
height = Form.ClientHeight - 45
OnClick = LoadImages
end create
end create
Form.ShowModal

SUB LoadImages
fDialog.Caption = "Open two image files"
fDialog.filter = "Picture files|*.BMP;*.ICO;*.JPG;*.GIF;*.TIF;*.PNG"
fDialog.FileName= ""
fDialog.MultiSelect = True
IF fDialog.Execute THEN
Src1.LoadFromFile(fDialog.Files(0) + fDialog.Files(1))
Src2.LoadFromFile(fDialog.Files(0) + fDialog.Files(2))
TmpBMP.AlphaBlend(Src1, Src2, 0.5) 'mix 50-50%
Canvas.Draw(0,0, TmpBMP.BMP)
END IF
END SUB

QBitmapEx Example 3 Using GDI+

$INCLUDE <gdiplus.inc>
$INCLUDE "rapidq2.inc"

DIM myBmp AS QBITMAPEX
myBmp.width = 512
myBmp.Height = 512
myBMP.PixelFormat = pf32bit 'must be 32-bit

DEFINT hStatus = myBMP.CreateGDIplusImage
IF hStatus THEN showmessage "err: " + myBMP.GDIStatus(hStatus)

DEFLNG pBrush, pGraphics
GdipGetImageGraphicsContext(myBMP.GDIplusImage, pGraphics)
GdipGraphicsClear(pGraphics, &HFF000088) ' color is AARRGGBB
GdipCreateSolidFill(&HFFFFFFFF, pBrush)
'Set the smoothing mode
GdipSetSmoothingMode(pGraphics, SmoothingModeHighQuality)
GdipFillEllipse(pGraphics, pBrush, 0, 0, 200, 100)
'turn off the smoothing mode
GdipSetSmoothingMode(pGraphics, SmoothingModeNone)
GdipFillEllipse(pGraphics, pBrush, 250, 0, 200, 100)
' // Cleanup
myBMP.CopyFromGDIplus
myBMP.SaveToFile ("test.jpg", 100)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
IF pBrush THEN GdipDeleteBrush(pBrush)
myBMP.DestroyGDIplusImage
myBMP.UseGDIplus = false


Prev Component Contents Next Component