Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/Images/JPEG/JPEGToString example
Function:
Required plugins for this example: MBS Images Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Images/JPEG/JPEGToString example
This example is the version from Fri, 17th Nov 2016.
Project "JPEGToString example.rbp"
FileTypes
Filetype image/jpeg
End FileTypes
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 StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control Quality Inherits Slider
ControlInstance Quality Inherits Slider
EventHandler Sub ValueChanged() value.text=str(me.value) run preview.graphics.drawpicture current,0,0 End EventHandler
End Control
Control value Inherits Label
ControlInstance value Inherits Label
End Control
Control size Inherits Label
ControlInstance size Inherits Label
End Control
Control CheckBox1 Inherits CheckBox
ControlInstance CheckBox1 Inherits CheckBox
EventHandler Sub Action() run End EventHandler
End Control
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) g.drawpicture current,0,0 End EventHandler
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
EventHandler Sub Open() create run End EventHandler
Sub create() dim x as integer dim y as integer dim r as RGBSurface dim w as integer dim g as Graphics dim h as integer original = New Picture(preview.width,preview.height,32) r=original.RGBSurface w=original.width-1 h=original.height-1 g=original.Graphics for x=0 to w for y=0 to h g.pixel(x,y)=rgb(x*255/w,y*255/h,y*255/h) next next Canvas1.Backdrop=original End Sub
Sub run() // whether class or function, both do the same! if CheckBox1.Value then runClass else runFunction end if End Sub
Protected Sub runClass() dim je as JPEGExporterMBS dim ji as JPEGImporterMBS dim s as String je=new JPEGExporterMBS ji=new JPEGImporterMBS je.Picture=original je.Quality=Quality.Value je.Export s=je.Data if je.ErrorCode=0 then ji.Data=s ji.AllowDamaged=true ji.Import current=ji.Picture size.text=str(lenb(s))+" Bytes" else msgBox "Error on creating the JPEG file." end if End Sub
Protected Sub runFunction() dim s as string dim f as folderItem dim b as binaryStream // compress picture s=PictureToJPEGStringMBS(original,quality.value) f=SpecialFolder.Desktop.child("PictureToJPEGString.jpg") b=f.createBinaryFile("image/jpeg") if b<>nil then b.write s b.close end if current=JPEGStringToPictureMBS(s,true) size.text=str(len(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
End Project

Feedback, Comments & Corrections

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




Links
MBS FileMaker Plugins