|
Post by held12345 on Mar 12, 2023 7:05:44 GMT -5
Hi good afternoon. I need help for :
Declare Function PlgBlt Lib "gdi32" ( _ ByVal hdcDest As Long, _ ByRef lpPoint As PointApi, _ ByVal hdcSrc As Long, _ ByVal nXSrc As Long, _ ByVal nYSrc As Long, _ ByVal nWidth As Long, _ ByVal nHeight As Long, _ ByVal hbmMask As Long, _ ByVal xMask As Long, _ ByVal yMask As Long) As Long
who can please help to turn a bmp with lbb?
tanks
|
|
|
Post by Rod on Mar 12, 2023 10:25:02 GMT -5
PLGBLT() is covered in the LBPE here alycesrestaurant.com/lbpe/PlgBlt.html However it does not actually "turn" a bmp it only takes a rectangular bmp and skews it to any parallelogram shape. If you actually want to "turn" ie rotate a bmp you need this example. But it is so complex I have rarely seen it put into action other than as a demo. [Setup] Open "oleaut32" For DLL As #oleaut32
NoMainWin WindowWidth = 500 WindowHeight = 500 UpperLeftX = Int(DisplayWidth-WindowWidth)/2 UpperLeftY = Int(DisplayHeight-WindowHeight)/2
GraphicsWidth = 500 : GraphicsHeight = 500 GraphicBox #Win.g, 0, 0, GraphicsWidth, GraphicsHeight
Open "Rotation Test" For Window_NF As #Win
#Win "TrapClose [Quit]" #Win.g "down; home" #Win.g "posxy CenterX CenterY"
LoadBMP "bitmap", "test.bmp"
imgWidth = 300 imgHeight = 300
' Get the handle to the graphicbox display: displayDC = GetDC(Hwnd(#Win.g))
memoryDC = CreateCompatibleDC(displayDC) hBitmap = Hbmp("bitmap")
result = SetGraphicsMode(memoryDC, _GM_ADVANCED) result = SetGraphicsMode(displayDC, _GM_ADVANCED)
oldBitmap = SelectObject(memoryDC, hBitmap)
Struct XFORM,_ eM11 As uLong,_ eM12 As uLong,_ eM21 As uLong,_ eM22 As uLong,_ eDx As uLong,_ eDy As uLong
angle = 0
Timer 17, [Draw] Wait
[Draw] ' Draw our image at the box center radians = Radian(angle) cosine = cos(radians) sine = sin(radians)
x1 = Int(imgHeight * sine) y1 = Int(imgHeight * cosine)
x2 = Int(imgWidth * cosine + imgHeight * sine) y2 = Int(imgHeight * cosine - imgWidth * sine)
x3 = Int(imgWidth * cosine) y3 = Int(-1*imgWidth * sine)
minx = min(0,min(x1, min(x2,x3))) miny = min(0,min(y1, min(y2,y3))) maxx = max(0,max(x1, max(x2,x3))) maxy = max(0,max(y1, max(y2,y3)))
width = maxx - minx height = maxy - miny
XFORM.eM11.struct = toFloat(cosine) XFORM.eM12.struct = toFloat(sine) XFORM.eM21.struct = toFloat(-1*sine) XFORM.eM22.struct = toFloat(cosine) XFORM.eDx.struct = toFloat(CenterX) XFORM.eDy.struct = toFloat(CenterY)
result = SetWorldTransform(displayDC)
Call BitBlt displayDC, int(imgWidth/-2), int(imgHeight/-2), imgWidth, imgHeight, memoryDC, 0, 0 angle = angle + 5 Wait
[Quit] ' Release the handle from the graphicbox display: Call ReleaseDC Hwnd(#Win.g), displayDC Call DeleteDC memoryDC Close #Win Close #oleaut32 End
Function Radian(angleDegrees) Radian = angleDegrees / 180 * acs(-1) End Function
Function SetWorldTransform(hDC) ' 0 = failure CallDLL #gdi32, "SetWorldTransform", hDC As uLong, XFORM as struct, SetWorldTransform As long End Function
Function SetGraphicsMode(hDC, mode) ' mode = 2 (advanced) (for setworldtransform()) ' mode = 1 (compatible) (default) CallDLL #gdi32, "SetGraphicsMode", hDC As uLong, mode As Long, Result As Long SetGraphicsMode = Result End Function
Function GetDC(hWnd) CallDLL #user32, "GetDC",_ hWnd As ulong,_ 'window or control handle GetDC As ulong 'returns device context End Function
Sub ReleaseDC hWnd, hDC CallDLL#user32,"ReleaseDC",_ hWnd As ulong,_ 'window or control handle hDC As ulong,_ 'handle of DC to delete result As Long End Sub
Function CreateCompatibleDC(hDC) CallDLL #gdi32,"CreateCompatibleDC",_ hDC As ulong,_ 'window DC CreateCompatibleDC As ulong 'memory DC End Function
Sub DeleteDC hDC CallDLL #gdi32, "DeleteDC",_ hDC As ulong,_ 'memory DC to delete r As long End Sub
Sub BitBlt hDCdest,x,y,w,h,hDCsrc,x2,y2 CallDLL #gdi32, "BitBlt",hDCdest As uLong,x As Long,y As Long,w As Long,h As Long,_ hDCsrc As uLong,x2 As Long,y2 As Long, _SRCCOPY As Ulong, Result As long End Sub
Function SelectObject(hDC,hObject) CallDLL #gdi32,"SelectObject",_ hDC As ulong,_ 'memory device context hObject As ulong,_ 'handle of object SelectObject As ulong 'returns previously selected object End Function
Function toFloat( R8 ) '-- Converts a 64-bit Double to a 32-bit number. Struct local1, R4 As ULong CallDLL #oleaut32, "VarR4FromR8", _ R8 As Double, local1 As Struct, _ ret As Long toFloat = local1.R4.struct End Function
Function fromFloat( R4 ) '-- Converts a 32-bit number to a 64-bit Double. Struct local1, R8 As Double CallDLL #oleaut32, "VarR8FromR4", _ R4 As ULong, local1 As Struct, _ ret As Long fromFloat = local1.R8.struct End Function
|
|
|
Post by held12345 on Mar 13, 2023 3:48:44 GMT -5
hello, thanks for help.
greeting.
|
|
|
Post by tsh73 on Mar 13, 2023 8:42:12 GMT -5
This code is a bit on top of Alice restaurant code If it is not rotation then what is rotation? 'now use drawn bitmap instead of opened one ' filedialog "Open","*.bmp",bmp$ ' if bmp$="" then end ' loadbmp "image",bmp$ nomainwin winWide=700:winHigh=500 WindowWidth=winWide+50:WindowHeight=winHigh+50 UpperLeftX=1:UpperLeftY=1 graphicbox #1.g, 0,0,winWide,winHigh open "Parallelogram Blt" for window as #1 #1 "trapclose [quit]" #1.g "down;fill lightgray; backcolor lightgray"
#1.g "down; home; posxy cx cy" #1.g "font arial bold 16" #1.g "\";" Hello" #1.g "\";"there!" #1.g "\";" Feel the" #1.g "\";"power of" #1.g "\";"BASIC!" #1.g "posxy dummy lastY" hy=(lastY-cy)/5 'line height #1.g "place ";cx-10;" ";cy-hy #1.g "box ";cx+100;" ";cy+5*hy
bmpw=110:bmph=6*hy #1.g "getbmp image ";cx-10;" ";cy-hy;" ";bmpw;" ";bmph #1.g "cls" #1.g "drawbmp image ";cx-50;" ";cy-2.5*hy 'wait
hImage=hbmp("image") struct BITMAP,_ bmType as long,_ bmWidth As long,_ bmHeight As long,_ bmWidthBytes As long,_ bmPlanes as word,_ bmBitsPixel as word,_ bmBits as Long length=len(BITMAP.struct) calldll #gdi32, "GetObjectA", hImage as ulong,_ length as long,BITMAP as struct,_ results as long bmpWidth=BITMAP.bmWidth.struct bmpHeight=BITMAP.bmHeight.struct h=hwnd(#1.g) 'graphicbox handle 'get device context for window: calldll #user32, "GetDC",_ h as ulong,_ 'graphicbox handle hdc as ulong 'returns handle to device context CallDLL #gdi32,"CreateCompatibleDC",_ hdc as uLong,_ memdc as uLong CallDLL #gdi32,"SelectObject",_ memdc as uLong,_ hImage as uLong,_ oldObject as uLong STRUCT lpPoint,_ x1 as long,_ 'ulx y1 as long,_ 'uly x2 as long,_ 'urx y2 as long,_ 'ury x3 as long,_ 'llx y3 as long 'lly '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 '1 2 '3 x1=-1*bmpw/2:y1=-1*bmph/2 'Y INVERTED x2=1*bmpw/2:y2=-1*bmph/2 x3=-1*bmpw/2:y3=1*bmph/2
r = 1 pi=acs(-1) cx=winWide/2:cy=winHigh/2
'initial pause TIMER 500, [NXT0] wait [NXT0] TIMER 0
for a = 30 to 360 step 10 aa=a*pi/180 c=cos(aa):s=sin(aa) 'The STRUCT must be filled before it can be used in an api call: lpPoint.x1.struct = int(cx+r*(c*x1-s*y1)) lpPoint.y1.struct = int(cy+r*(s*x1+c*y1)) lpPoint.x2.struct = int(cx+r*(c*x2-s*y2)) lpPoint.y2.struct = int(cy+r*(s*x2+c*y2)) lpPoint.x3.struct = int(cx+r*(c*x3-s*y3)) lpPoint.y3.struct = int(cy+r*(s*x3+c*y3)) calldll #gdi32, "PlgBlt",_ hdc as ulong,_ 'device context of graphicbox lpPoint as struct,_ 'array of points memdc as ulong,_ 'memory DC 0 as long,_ 'ulx source 0 as long,_ 'uly source bmpWidth as long,_ 'width source bmpHeight as long,_ 'height source 0 as ulong,_ 'mask bmp handle, null = not used 0 as long,_ 'ulx mask 0 as long,_ 'uly mask re as long 'nonzero=success 'method to flush GDI graphics: '#1.g "getbmp pix 0 0 ";winWide;" ";winHigh '#1.g "drawbmp pix 0 0;flush" 'TIMER 50, [NXT] TIMER 100, [NXT]
wait [NXT] TIMER 0
NEXT
WAIT [quit] calldll #user32, "ReleaseDC",_ h as ulong,_ 'window handle hdc as ulong,_ 'device context ret as long CallDLL #gdi32, "DeleteDC",memdc as uLong, r As long close #1:end
|
|
|
Post by Rod on Mar 13, 2023 9:37:10 GMT -5
Oh nice! I tried years ago and did not get rotation, poor maths! also Microsofts own words deflected me "Scaling, translation, and reflection transformations are allowed in the source device context; however, rotation and shear transformations are not."
Thats probably the simplest rotation, much simpler than OpenGL.
|
|
|
Post by held12345 on Mar 13, 2023 11:31:52 GMT -5
hello tsh73 , this is wonderfull. how can i load my bmp128x128 there now please.
thanks greeting
|
|
|
Post by tsh73 on Mar 13, 2023 12:16:02 GMT -5
loadbmp "image","c:\path\to your\bmp128x128.bmp"
After that it is loaded as "image".
|
|
|
Post by held12345 on Mar 13, 2023 14:12:22 GMT -5
where does that come from below in the program so that the sprite is rotated? loadbmp "image","sprites\auto.bmp"
thanks greeting
------------------------------ nomainwin winWide=700:winHigh=500 WindowWidth=winWide+50:WindowHeight=winHigh+50 UpperLeftX=1:UpperLeftY=1 graphicbox #1.g, 0,0,winWide,winHigh open "Parallelogram Blt" for window as #1 #1 "trapclose [quit]" #1.g "down;fill lightgray; backcolor lightgray"
#1.g "down; home; posxy cx cy" #1.g "font arial bold 16" #1.g "\";" Hello" #1.g "\";"there!" #1.g "\";" Feel the" #1.g "\";"power of" #1.g "\";"BASIC!" #1.g "posxy dummy lastY" hy=(lastY-cy)/5 'line height #1.g "place ";cx-10;" ";cy-hy #1.g "box ";cx+100;" ";cy+5*hy
bmpw=110:bmph=6*hy #1.g "getbmp image ";cx-10;" ";cy-hy;" ";bmpw;" ";bmph #1.g "cls" #1.g "drawbmp image ";cx-50;" ";cy-2.5*hy 'wait
hImage=hbmp("image") struct BITMAP,_ bmType as long,_ bmWidth As long,_ bmHeight As long,_ bmWidthBytes As long,_ bmPlanes as word,_ bmBitsPixel as word,_ bmBits as Long length=len(BITMAP.struct) calldll #gdi32, "GetObjectA", hImage as ulong,_ length as long,BITMAP as struct,_ results as long bmpWidth=BITMAP.bmWidth.struct bmpHeight=BITMAP.bmHeight.struct h=hwnd(#1.g) 'graphicbox handle 'get device context for window: calldll #user32, "GetDC",_ h as ulong,_ 'graphicbox handle hdc as ulong 'returns handle to device context CallDLL #gdi32,"CreateCompatibleDC",_ hdc as uLong,_ memdc as uLong CallDLL #gdi32,"SelectObject",_ memdc as uLong,_ hImage as uLong,_ oldObject as uLong STRUCT lpPoint,_ x1 as long,_ 'ulx y1 as long,_ 'uly x2 as long,_ 'urx y2 as long,_ 'ury x3 as long,_ 'llx y3 as long 'lly '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 '1 2 '3 x1=-1*bmpw/2:y1=-1*bmph/2 'Y INVERTED x2=1*bmpw/2:y2=-1*bmph/2 x3=-1*bmpw/2:y3=1*bmph/2
r = 1 pi=acs(-1) cx=winWide/2:cy=winHigh/2
'initial pause TIMER 500, [NXT0] wait [NXT0] TIMER 0
for a = 30 to 360 step 10 aa=a*pi/180 c=cos(aa):s=sin(aa) 'The STRUCT must be filled before it can be used in an api call: lpPoint.x1.struct = int(cx+r*(c*x1-s*y1)) lpPoint.y1.struct = int(cy+r*(s*x1+c*y1)) lpPoint.x2.struct = int(cx+r*(c*x2-s*y2)) lpPoint.y2.struct = int(cy+r*(s*x2+c*y2)) lpPoint.x3.struct = int(cx+r*(c*x3-s*y3)) lpPoint.y3.struct = int(cy+r*(s*x3+c*y3)) calldll #gdi32, "PlgBlt",_ hdc as ulong,_ 'device context of graphicbox lpPoint as struct,_ 'array of points memdc as ulong,_ 'memory DC 0 as long,_ 'ulx source 0 as long,_ 'uly source bmpWidth as long,_ 'width source bmpHeight as long,_ 'height source 0 as ulong,_ 'mask bmp handle, null = not used 0 as long,_ 'ulx mask 0 as long,_ 'uly mask re as long 'nonzero=success 'method to flush GDI graphics: '#1.g "getbmp pix 0 0 ";winWide;" ";winHigh '#1.g "drawbmp pix 0 0;flush" 'TIMER 50, [NXT] TIMER 100, [NXT]
wait [NXT] TIMER 0
NEXT
WAIT [quit] calldll #user32, "ReleaseDC",_ h as ulong,_ 'window handle hdc as ulong,_ 'device context ret as long CallDLL #gdi32, "DeleteDC",memdc as uLong, r As long close #1:end ---------------------------
|
|
|
Post by tsh73 on Mar 13, 2023 16:30:08 GMT -5
Here you are It even takes picture dimensions from bitmap loaded
'now use drawn bitmap instead of opened one ' filedialog "Open","*.bmp",bmp$ ' if bmp$="" then end ' loadbmp "image",bmp$
nomainwin winWide=700:winHigh=500 WindowWidth=winWide+50:WindowHeight=winHigh+50 UpperLeftX=1:UpperLeftY=1
graphicbox #1.g, 0,0,winWide,winHigh open "Parallelogram Blt" for window as #1 #1 "trapclose [quit]" #1.g "down;fill lightgray; backcolor lightgray" #1.g "home; posxy cx cy"
loadbmp "image","sprites\auto.bmp" 'loadbmp "image","sprites\new1.bmp"
'wait
hImage=hbmp("image")
struct BITMAP,_ bmType as long,_ bmWidth As long,_ bmHeight As long,_ bmWidthBytes As long,_ bmPlanes as word,_ bmBitsPixel as word,_ bmBits as Long length=len(BITMAP.struct) calldll #gdi32, "GetObjectA", hImage as ulong,_ length as long,BITMAP as struct,_ results as long
bmpWidth=BITMAP.bmWidth.struct bmpHeight=BITMAP.bmHeight.struct
#1.g "cls" #1.g "drawbmp image ";cx-bmpWidth/2;" ";cy-bmpHeight/2
h=hwnd(#1.g) 'graphicbox handle
'get device context for window: calldll #user32, "GetDC",_ h as ulong,_ 'graphicbox handle hdc as ulong 'returns handle to device context
CallDLL #gdi32,"CreateCompatibleDC",_ hdc as uLong,_ memdc as uLong
CallDLL #gdi32,"SelectObject",_ memdc as uLong,_ hImage as uLong,_ oldObject as uLong
STRUCT lpPoint,_ x1 as long,_ 'ulx y1 as long,_ 'uly x2 as long,_ 'urx y2 as long,_ 'ury x3 as long,_ 'llx y3 as long 'lly
'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 '1 2 '3 x1=-1*bmpWidth/2:y1=-1*bmpHeight/2 'Y INVERTED x2=1*bmpWidth/2:y2=-1*bmpHeight/2 x3=-1*bmpWidth/2:y3=1*bmpHeight/2
r = 1 pi=acs(-1) cx=winWide/2:cy=winHigh/2
'initial pause TIMER 500, [NXT0] wait [NXT0] TIMER 0
for a = 30 to 360 step 10 aa=a*pi/180 c=cos(aa):s=sin(aa)
'The STRUCT must be filled before it can be used in an api call:
lpPoint.x1.struct = int(cx+r*(c*x1-s*y1)) lpPoint.y1.struct = int(cy+r*(s*x1+c*y1)) lpPoint.x2.struct = int(cx+r*(c*x2-s*y2)) lpPoint.y2.struct = int(cy+r*(s*x2+c*y2)) lpPoint.x3.struct = int(cx+r*(c*x3-s*y3)) lpPoint.y3.struct = int(cy+r*(s*x3+c*y3))
calldll #gdi32, "PlgBlt",_ hdc as ulong,_ 'device context of graphicbox lpPoint as struct,_ 'array of points memdc as ulong,_ 'memory DC 0 as long,_ 'ulx source 0 as long,_ 'uly source bmpWidth as long,_ 'width source bmpHeight as long,_ 'height source 0 as ulong,_ 'mask bmp handle, null = not used 0 as long,_ 'ulx mask 0 as long,_ 'uly mask re as long 'nonzero=success
'method to flush GDI graphics: '#1.g "getbmp pix 0 0 ";winWide;" ";winHigh '#1.g "drawbmp pix 0 0;flush"
'TIMER 50, [NXT] TIMER 100, [NXT]
wait [NXT] TIMER 0
NEXT
WAIT
[quit] calldll #user32, "ReleaseDC",_ h as ulong,_ 'window handle hdc as ulong,_ 'device context ret as long
CallDLL #gdi32, "DeleteDC",memdc as uLong, r As long close #1:end
|
|
|
Post by held12345 on Mar 13, 2023 17:10:38 GMT -5
Hi, Thank You. you are classe and a master. now the bmp image rotates wonderfully evenly.
greeting
|
|