Xojo Conferences
MBSSep2018MunichDE
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCocoa/NSImage/Open Image using NSImage
Function:
Required plugins for this example: MBS MacBase Plugin, MBS MacCG Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/NSImage/Open Image using NSImage
This example is the version from Mon, 16th Mar 2014.
Project "Open Image using NSImage.rbp"
FileTypes
Filetype text
Filetype all
End FileTypes
Class Window1 Inherits Window
EventHandler Sub DropObject(obj As DragItem, action As Integer) if obj.FolderItemAvailable then process obj.FolderItem end if End EventHandler
EventHandler Sub Open() me.AcceptFileDrop "all" End EventHandler
Protected Sub process(f as folderitem) dim p as Picture p=f.OpenAsNSImage if p<>Nil then Backdrop=p MaxWidth=p.Width MaxHeight=p.Height else MsgBox "Could not read picture from "+f.Name end if End Sub
End Class
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
EventHandler Sub Open() if TargetMachO=false then MsgBox "This example needs a MachO target running on Mac OS X." quit end if End EventHandler
End Class
Module Module1
Function OpenAsNSimage(extends file as folderitem) As picture // this one is resolution indepenend! dim width as integer dim height as integer dim c as NSImageMBS dim g as CGPictureContextMBS // load image from file c=new NSImageMBS(file) // is that image valid? if c.isValid then Width=c.MaximumPixelWidth height=c.MaximumPixelHeight // We want maximum size of pixels! c.ScalesWhenResized = True c.SetSize width,height // create a drawing buffer to draw inside g=new CGPictureContextMBS(width,height) if g.Handle<>0 then // valid? // now draw the image inside. // you could scale or even apply transparency... if c.DrawIntoCGContextAtRect(g.Handle, 0, 0, c.width, c.height, 0,0,c.width,c.height,2,1.0) then // make a RB Picture from it Return g.CopyPicture end if end if end if End Function
End Module
End Project

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS MacCocoa Plugin.





Links
MBS FileMaker Plugins