aus dem Speicher bekommt, einmal mit einem Sprite
das zweite mit SetDIBits.
escapi.pbi
Code: Alles auswählen
; escapi.pbi
;
; http://sol.gfxile.net/escapi/index.html
Structure SimpleCapParams
*mTargetBuf.i ; Must be at least mWidth * mHeight * SizeOf(int) of size!
mWidth.l
mHeight.l
EndStructure
Global escapiDLL.i
;- Prototype
PrototypeC.l ESCAPIDLLVersion()
PrototypeC.l countCaptureDevices()
PrototypeC.l deinitCapture(deviceno.l)
PrototypeC.l doCapture(deviceno.l)
PrototypeC.l getCaptureDeviceName(deviceno.l, *namebuffer.i, bufferlength.l)
PrototypeC.l initCOM()
PrototypeC.l initCapture(deviceno.l, *SimpleCapParams.i)
PrototypeC.l isCaptureDone(deviceno.l)
Procedure escapiClose()
If escapiDLL > 0
If IsLibrary(escapiDLL)
CloseLibrary(escapiDLL)
EndIf
escapiDLL = 0
EndIf
EndProcedure
Procedure escapiOpen()
escapiDLL = OpenLibrary(#PB_Any, "escapi.dll")
If escapiDLL = 0
ProcedureReturn #False
EndIf
Global ESCAPIDLLVersion.ESCAPIDLLVersion=GetFunction(escapiDLL,"ESCAPIDLLVersion")
Global countCaptureDevices.countCaptureDevices=GetFunction(escapiDLL,"countCaptureDevices")
Global deinitCapture.deinitCapture=GetFunction(escapiDLL,"deinitCapture")
Global doCapture.doCapture=GetFunction(escapiDLL,"doCapture")
Global getCaptureDeviceName.getCaptureDeviceName=GetFunction(escapiDLL,"getCaptureDeviceName")
Global initCOM.initCOM=GetFunction(escapiDLL,"initCOM")
Global initCapture.initCapture=GetFunction(escapiDLL,"initCapture")
Global isCaptureDone.isCaptureDone=GetFunction(escapiDLL,"isCaptureDone")
ProcedureReturn #True
EndProcedure
Code: Alles auswählen
EnableExplicit
IncludeFile "escapi.pbi"
Define deviceno.l, version.l, count.l, *namebuffer.i, bufferlength.l, name$, quit.l
Define width, height, res.i, size.i, buffer.i, sprite.i
Define scp.SimpleCapParams
deviceno = 0
width = 320
height = 240
If InitSprite() = 0
End
EndIf
If escapiOpen()
version = ESCAPIDLLVersion()
Debug "version: $" + RSet(Hex(version), 4, "0")
initCOM()
count = countCaptureDevices()
Debug "count: " + Str(count)
If count > 0
*namebuffer = AllocateMemory(1000)
bufferlength = 1000
getCaptureDeviceName(deviceno, *namebuffer, bufferlength)
If *namebuffer > 0
name$ = PeekS(*namebuffer, -1, #PB_Ascii)
Debug "name: " + name$
EndIf
scp\mWidth = width
scp\mHeight = height
size = scp\mWidth * scp\mHeight * 4
scp\mTargetBuf = AllocateMemory(size)
If initCapture(deviceno, @scp)
Debug "cap init successful"
OpenWindow(0, 450, 200, width, height, name$, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar)
OpenWindowedScreen(WindowID(0), 0, 0, width, height, 0, 0, 0)
sprite = CreateSprite(#PB_Any, width, height)
Repeat
doCapture(deviceno)
While isCaptureDone(deviceno) = 0
If WaitWindowEvent(1) = #PB_Event_CloseWindow
quit = 1
Break
EndIf
Wend
StartDrawing(SpriteOutput(sprite))
buffer = DrawingBuffer()
StopDrawing()
CopyMemory(scp\mTargetBuf, buffer, size)
DisplaySprite(sprite, 0, 0)
FlipBuffers()
Until quit = 1
deinitCapture(deviceno)
Else
Debug "init capture failed!"
EndIf
If *namebuffer > 0
FreeMemory(*namebuffer)
EndIf
If scp\mTargetBuf > 0
FreeMemory(scp\mTargetBuf)
EndIf
EndIf
escapiClose()
Else
MessageRequester("example", "DLL 'escapi.dll' nicht vorhanden!")
EndIf
End
Code: Alles auswählen
EnableExplicit
IncludeFile "escapi.pbi"
Define deviceno.l, version.l, count.l, *namebuffer.i, bufferlength.l, name$, quit.l
Define width, height, size.i, image.i, hBmp.i, hdc.i
Define bmi.BITMAPINFO, scp.SimpleCapParams
deviceno = 0
width = 320
height = 240
If escapiOpen()
version = ESCAPIDLLVersion()
Debug "version: $" + RSet(Hex(version), 4, "0")
initCOM()
count = countCaptureDevices()
Debug "count: " + Str(count)
If count > 0
*namebuffer = AllocateMemory(1000)
bufferlength = 1000
getCaptureDeviceName(deviceno, *namebuffer, bufferlength)
If *namebuffer > 0
name$ = PeekS(*namebuffer, -1, #PB_Ascii)
Debug "name: " + name$
EndIf
bmi\bmiHeader\biSize = SizeOf(BITMAPINFOHEADER)
bmi\bmiHeader\biWidth = width
bmi\bmiHeader\biHeight = - height
bmi\bmiHeader\biPlanes = 1
bmi\bmiHeader\biBitCount = 32
bmi\bmiHeader\biCompression = #BI_RGB
scp\mWidth = width
scp\mHeight = height
size = scp\mWidth * scp\mHeight * 4
scp\mTargetBuf = AllocateMemory(Size)
If initCapture(deviceno, @scp)
Debug "cap init successful"
image = CreateImage(#PB_Any, width, height, 32)
hBmp = ImageID(image)
OpenWindow(0, 450, 200, width, height, name$, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar)
ImageGadget(0, 0, 0, width, height, ImageID(image))
Repeat
doCapture(deviceno)
While isCaptureDone(deviceno) = 0
If WaitWindowEvent(1) = #PB_Event_CloseWindow
quit = 1
Break
EndIf
Wend
hdc = StartDrawing(ImageOutput(image))
If hdc
SetDIBits_(hdc, hBmp, 0, height, scp\mTargetBuf, @bmi, #DIB_RGB_COLORS)
StopDrawing()
SetGadgetState(0, ImageID(image))
EndIf
Until quit = 1
deinitCapture(deviceno)
Else
Debug "init capture failed!"
EndIf
If *namebuffer > 0
FreeMemory(*namebuffer)
EndIf
If scp\mTargetBuf > 0
FreeMemory(scp\mTargetBuf)
EndIf
EndIf
escapiClose()
Else
MessageRequester("example", "DLL 'escapi.dll' nicht vorhanden!")
EndIf
End