Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS Cameras Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Cameras/NikonCamera/Nikon
This example is the version from Tue, 23th May 2016.
Project "Nikon.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
EventHandler Sub Open()
AutoQuit = true
m = new MyNikonMBS
run
m = nil
End EventHandler
Sub Run()
if m.LoadLibrary("/Library/Application Support/Nikon/Camera Control Modules/Type0005 Module.bundle") = false then
MsgBox "Failed to load module."
Return
end if
if m.OpenModule = false then
MsgBox "Failed to open module."
Return
end if
const kNkMAIDCapability_Name = 9
MsgBox "Module: "+m.GetCapString(m.kModule, kNkMAIDCapability_Name)
if m.OpenSource(0) = false then
MsgBox "Failed to open first device."
Return
end if
MsgBox "Device: "+m.GetCapString(m.kDevice, kNkMAIDCapability_Name)
while m.Capture = false
// try again
wend
// wait some time
dim n as integer = 1
do
n = n + 1
DoEvents 100
call m.Async_
if m.OpenItem(0) then
exit // ok
else
if n>20 then
MsgBox "Failed to open first image."
Return
end if
end if
loop
'MsgBox m.GetCapString(m.kItem, kNkMAIDCapability_Name)
if m.OpenData(m.kDataObjTypeImage) = false then
MsgBox "Failed to open first image's data."
Return
end if
if not m.Acquire then
MsgBox "Failed to acquire."
Return
end if
MsgBox "OK"
End Sub
Note "Credits"
Example code created by Christian Schmitz
and Christopher Rosado
Property m As MyNikonMBS
End Class
Class PicWindow Inherits Window
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect)
// Calculate scale factor
if pic<>Nil then
dim faktor as Double = min( g.Height / Pic.Height, g.Width / Pic.Width)
// Calculate new size
dim w as integer = Pic.Width * faktor
dim h as integer = Pic.Height * faktor
dim x as integer = (g.width-w)/2
dim y as integer = (g.height-h)/2
// draw picture in the new size
g.DrawPicture Pic, x, y, w, h, 0, 0, Pic.Width, Pic.Height
end if
End EventHandler
Property pic As Picture
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
Class MyNIkonMBS Inherits NikonMBS
EventHandler Sub FileDownloadComplete(info as NikonFileInfoMBS, data as Memoryblock, length as Integer)
// does only work if file is a JPEG
dim pic as Picture = Picture.FromData(Data)
dim w as new picwindow
w.pic = pic
w.title = "JPEG File"
End EventHandler
EventHandler Sub ImageDownloadComplete(info as NikonImageInfoMBS, data as Memoryblock, length as Integer)
// maybe does not work if data is raw pixels!
dim pic as Picture = Picture.FromData(Data)
dim w as new picwindow
w.pic = pic
w.Title = "Image"
End EventHandler
EventHandler Sub Progress(Command as integer, Param as Integer, Done as UInt32, Total as UInt32, Percent as double)
System.DebugLog "Progress: "+Format(Percent/100.0,"0%")
End EventHandler
End Class
End Project
See also:
The items on this page are in the following plugins: MBS Cameras Plugin.