You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Picture/BinaryPicture
Class Window1 Inherits Window
Control preview Inherits Canvas
ControlInstance preview Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect)
g.drawpicture current,0,0
End EventHandler
End Control
Control size Inherits Label
ControlInstance size Inherits Label
End Control
EventHandler Sub Open()
create
run
End EventHandler
Sub create()
dim g as graphics
dim x as integer
dim y as integer
dim r as RGBSurface
dim w as integer
dim h as integer
original = new Picture(preview.width,preview.height,32)
r=original.RGBSurface
g=original.graphics
w=original.width-1
h=original.height-1
for x=0 to w
for y=0 to h
r.pixel(x,y)=rgb(x*255/w,y*255/h,y*255/h)
next
next
End Sub
Sub run()
dim s as string
// compress picture
s=PicturetoBinaryStringMBS(original)
current=BinaryStringtoPictureMBS(s)
size.text=str(lenb(s))+" Bytes"
End Sub
Property current As picture
Property original As picture
End Class
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
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