Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

/Images/JPEG/VirtualVolume Demo
Required plugins for this example: MBS Images Plugin, MBS Picture Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Images/JPEG/VirtualVolume Demo
This example is the version from Thu, 6th Apr 2016.
Project "VirtualVolume Demo.rbp"
Filetype myBinary
Filetype image/gif
Filetype image/jpeg
End FileTypes
Class MainWindow1 Inherits Window
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
EventHandler Sub DropObject(obj As DragItem, action As Integer) if obj.pictureAvailable then me.backdrop = obj.picture end if if obj.folderItemAvailable then me.backdrop = obj.folderItem.openAsPicture end if End EventHandler
EventHandler Sub Open() me.acceptPictureDrop me.acceptFileDrop("image/gif") me.acceptFileDrop("image/jpeg") End EventHandler
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) g.drawRect(0, 0, g.width - 1, g.height - 1) End EventHandler
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() if canvas1.backdrop <> nil then BinarySave else beep end if End EventHandler
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action() BinaryLoad End EventHandler
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control PushButton3 Inherits PushButton
ControlInstance PushButton3 Inherits PushButton
EventHandler Sub Action() Canvas1.Backdrop = Nil End EventHandler
End Control
Function FileOpen() As Boolean End Function
Sub BinaryLoad() dim BinIn as binaryStream dim f, VVFile as folderItem dim vv As VirtualVolume dim s as String ' Start by selecting out Virtual Volume, and getting a FolderItem ' to ClipArt within it. VVFile = SpecialFolder.Desktop.Child("VV File") vv = VVFile.OpenAsVirtualVolume f = vv.Root.Child("ClipArt.jpg") ' Check our FolderItems were created ok. if f <> nil then ' Get a Binary Stream to read from ClipArt from within the VV. BinIn = f.OpenAsBinaryFile(false) if BinIn <> nil then ' Creat a Binary Stream to write to. s=BinIn.read(BinIn.Length) if s<>"" then Canvas1.backdrop = JPEGStringToPictureMBS(s,true) end if BinIn.close end if ' in = nil end if ' f = nil End Sub
Sub BinarySave() dim BinOut as binaryStream dim f, VVFile, SaveFile as folderItem dim i, n as integer dim vv As VirtualVolume dim s as String dim p as Picture ' Basic Process: ' We can't save directly to a virtual volume as a picture file ' but a picture file is simply a binary file, and that we can do. ' But to get the directy binary data out of the picture we need to first ' save it somewhere, such as the TemporaryFolder. Then we just need ' to read everything from that file as a binary stream and write it into ' our Virtual Volume. ' Start by creating the VirtualVolume and setting up our FolderItem ' to save the pic to. VVFile = SpecialFolder.Desktop.Child("VV File") vv = VVFile.CreateVirtualVolume f = vv.Root.Child("ClipArt.jpg") p=Canvas1.Backdrop if p<>Nil then p=p.BitmapMBS // Make sure it's a bitmap picture. s=PictureToJPEGStringMBS(p,100) end if ' Check that both FolderItems have been created ok. if s<>"" and f <> nil then ' Create our binary stream to save to. BinOut = f.CreateBinaryFile("myBinary") if BinOut <> nil then BinOut.write s end if BinOut.close end if ' f = nil End Sub
Property totalwords As integer
End Class
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileOpen = "Open"
MenuItem FileSave = "Save"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
End Class
End Project

Feedback, Comments & Corrections

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

MBS Xojo Plugins