Thanks

Code: Select all
EnableExplicit
ImportC "/System/Library/Frameworks/QTKit.framework/QTKit" : EndImport
ImportC ""
sel_registerName(MethodName.P-ASCII)
class_addMethod(Class.I, Selector.I, Implementation.I, Types.P-ASCII)
EndImport
Define Delegate.I
Define DelegateClass.I
Define Device.I
Define DeviceInput.I
Define NSError.I
Define Session.I
Define TakeSnapshotNow.I
Define View.I
ProcedureC SnapshotCallback(Object.I, Selector.I, View.I, CIImage.I)
Shared TakeSnapshotNow.I
Protected CGImage.I
Protected NSCIImageRep.I
Protected NSImage.I
Protected ImageSize.NSSize
If TakeSnapshotNow
TakeSnapshotNow = #False
NSCIImageRep = CocoaMessage(0, CocoaMessage(0, 0,
"NSBitmapImageRep alloc"), "initWithCIImage:", CIImage)
If NSCIImageRep
CGImage = CocoaMessage(0, NSCIImageRep, "CGImage")
If CGImage
NSImage = CocoaMessage(0, 0, "NSImage alloc")
If NSImage
ImageSize\width = WindowWidth(1) + 4
ImageSize\height = WindowHeight(1) + 4
CocoaMessage(0, NSImage, "initWithCGImage:", CGImage,
"size:@", @ImageSize)
SetGadgetState(0, NSImage)
CocoaMessage(0, NSImage, "release")
EndIf
EndIf
EndIf
EndIf
EndProcedure
Delegate = CocoaMessage(0, CocoaMessage(0, 0,
"NSApplication sharedApplication"), "delegate")
DelegateClass = CocoaMessage(0, Delegate, "class")
class_addMethod(DelegateClass, sel_registerName("view:willDisplayImage:"),
@SnapshotCallback(), "v@:@@")
OpenWindow(0, 270, 100, 376, 300, "Press toolbar button for snapshot")
CreateImage(0, 16, 16)
StartDrawing(ImageOutput(0))
Box(0, 0, 16, 16, $FFFFFF)
Box(4, 4, 8, 8, $FF)
StopDrawing()
If CreateToolBar(0, WindowID(0))
ToolBarImageButton(0, ImageID(0))
EndIf
OpenWindow(1, WindowX(0) + WindowWidth(0) + 10, 132, WindowWidth(0),
WindowHeight(0), "Captured image",
#PB_Window_SystemMenu | #PB_Window_Invisible)
ImageGadget(0, 0, 0, WindowWidth(1), WindowHeight(1), 0)
CocoaMessage(0, GadgetID(0), "setImageScaling:", 0)
Session = CocoaMessage(0, CocoaMessage(0, 0, "QTCaptureSession alloc"), "init")
If Session
View = CocoaMessage(0, CocoaMessage(0, 0, "QTCaptureView alloc"), "init")
If View
CocoaMessage(0, View, "setDelegate:", Delegate)
CocoaMessage(0, WindowID(0), "setContentView:", View)
Device = CocoaMessage(0, 0,
"QTCaptureDevice defaultInputDeviceWithMediaType:$", @"vide")
If Device
If CocoaMessage(0, Device, "open:", @NSError) = #YES
DeviceInput = CocoaMessage(0, CocoaMessage(0, 0,
"QTCaptureDeviceInput alloc"), "initWithDevice:", Device)
If DeviceInput
If CocoaMessage(0, Session, "addInput:", DeviceInput, "error:",
@NSError) = #YES
CocoaMessage(0, View, "setCaptureSession:", Session)
CocoaMessage(0, Session, "startRunning")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Menu
If EventMenu() = 0
TakeSnapshotNow = #True
HideWindow(1, #False)
EndIf
EndSelect
ForEver
CocoaMessage(0, Session, "stopRunning")
CocoaMessage(0, Device, "close")
CocoaMessage(0, DeviceInput, "release")
CocoaMessage(0, Session, "release")
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
Code: Select all
EnableExplicit
ImportC "/System/Library/Frameworks/QTKit.framework/QTKit" : EndImport
ImportC ""
sel_registerName(MethodName.P-ASCII)
class_addMethod(Class.I, Selector.I, Implementation.I, Types.P-ASCII)
EndImport
Define Delegate.I
Define DelegateClass.I
Define Device.I
Define DeviceInput.I
Define NSError.I
Define Session.I
Define SnapshotFile.S = GetTemporaryDirectory() + "Snapshot.jpg"
Define TakeSnapshotNow.I
Define View.I
ProcedureC SnapshotCallback(Object.I, Selector.I, View.I, CIImage.I)
Shared SnapshotFile.S
Shared TakeSnapshotNow.I
Protected NSCIImageRep.I
Protected NSData.I
If TakeSnapshotNow
NSCIImageRep = CocoaMessage(0, CocoaMessage(0, 0, "NSBitmapImageRep alloc"), "initWithCIImage:", CIImage)
NSData = CocoaMessage(0, NSCIImageRep, "representationUsingType:", #NSJPEGFileType, "properties:", 0)
If CocoaMessage(0, NSData, "writeToFile:$", @SnapshotFile,
"atomically:", #NO) = #YES
EndIf
PostEvent(#PB_Event_CloseWindow)
EndIf
EndProcedure
Delegate = CocoaMessage(0, CocoaMessage(0, 0, "NSApplication sharedApplication"), "delegate")
DelegateClass = CocoaMessage(0, Delegate, "class")
class_addMethod(DelegateClass, sel_registerName("view:willDisplayImage:"), @SnapshotCallback(), "v@:@@")
OpenWindow(0, 270, 100, 376, 300, "Press toolbar button for snapshot")
CreateImage(0, 16, 16)
StartDrawing(ImageOutput(0))
Box(0, 0, 16, 16, $FFFFFF)
Box(4, 4, 8, 8, $FF)
StopDrawing()
If CreateToolBar(0, WindowID(0))
ToolBarImageButton(0, ImageID(0))
EndIf
Session = CocoaMessage(0, CocoaMessage(0, 0, "QTCaptureSession alloc"), "init")
If Session
View = CocoaMessage(0, CocoaMessage(0, 0, "QTCaptureView alloc"), "init")
If View
CocoaMessage(0, View, "setDelegate:", Delegate)
CocoaMessage(0, WindowID(0), "setContentView:", View)
Device = CocoaMessage(0, 0, "QTCaptureDevice defaultInputDeviceWithMediaType:$", @"vide")
If Device
If CocoaMessage(0, Device, "open:", @NSError) = #YES
DeviceInput = CocoaMessage(0, CocoaMessage(0, 0,
"QTCaptureDeviceInput alloc"), "initWithDevice:", Device)
If DeviceInput
If CocoaMessage(0, Session, "addInput:", DeviceInput, "error:", @NSError) = #YES
CocoaMessage(0, View, "setCaptureSession:", Session)
CocoaMessage(0, Session, "startRunning")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
If TakeSnapshotNow
CloseWindow(0)
MessageRequester("Info", "Snapshot was saved to " + SnapshotFile)
EndIf
Break
Case #PB_Event_Menu
If EventMenu() = 0
TakeSnapshotNow = #True
EndIf
EndSelect
ForEver
CocoaMessage(0, Session, "stopRunning")
CocoaMessage(0, Device, "close")
CocoaMessage(0, DeviceInput, "release")
CocoaMessage(0, Session, "release")
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
I am getting the exact same thing on my iMac with built-in cam.WilliamL wrote:Shardik,
I'm getting the stream, in a window, and when I click the toolbar I get another window (the correct size) but it is white.
WilliamL wrote:Hey Shardik, that works! I got the jpg in the temp folder but I thought it would be George Clooney and it was just me.![]()
I only mentioned that it didn't work but did not want to bother you further. If I had wanted it badly I would have been more specific. I have no idea why it would be different on my laptop and I surely don't expect you to know. I'm not that interested in looking at myself.
I appreciate all your contributions and want to try most of them just to see how they work.
Thanks again.
@spacebuddy.. nice to hear from you, I hate it when I'm the only one with the odd result.