Platforms to show: All Mac Windows Linux Cross-Platform
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/JPEG Modes
This example is the version from Fri, 17th Nov 2016.
Project "JPEG Modes.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
End Control
Control Canvas2 Inherits Canvas
ControlInstance Canvas2 Inherits Canvas
End Control
Control Canvas3 Inherits Canvas
ControlInstance Canvas3 Inherits Canvas
End Control
Control Canvas4 Inherits Canvas
ControlInstance Canvas4 Inherits Canvas
End Control
EventHandler Sub Open()
testPicture
testGrayPicture
testDataGray
testDataRGB
End EventHandler
Function MemToGrayPicture(m as MemoryBlock, width as integer, height as integer) As Picture
dim v,n,x,y,w,h as integer
dim p as Picture
dim r as RGBSurface
p = New Picture(width, height, 32)
r=p.RGBSurface
w=width-1
h=height-1
for y=0 to h
for x=0 to w
v=m.Byte(n)
r.Pixel(x,y)=rgb(v,v,v)
n=n+1
next
next
Return p
End Function
Function MemToRGBPicture(m as MemoryBlock, width as integer, height as integer) As Picture
dim r,g,b,n,x,y,w,h as integer
dim p as Picture
dim rr as RGBSurface
p = New Picture(width, height, 32)
rr=p.RGBSurface
w=width-1
h=height-1
for y=0 to h
for x=0 to w
r=m.Byte(n)
n=n+1
g=m.Byte(n)
n=n+1
b=m.Byte(n)
n=n+1
rr.Pixel(x,y)=rgb(r,g,b)
next
next
Return p
End Function
Sub testDataGray()
dim j as new JPEGImporterMbs
dim f as FolderItem
f=SpecialFolder.Desktop.Child("gray.jpg")
j.File=f
j.Mode=j.ModeGray
j.Import
if j.Picture=nil and j.PictureData<>nil then
Canvas4.Backdrop=MemToGrayPicture(j.PictureData,j.Width,j.Height)
else
MsgBox "ModeGray failed"
end if
End Sub
Sub testDataRGB()
dim j as new JPEGImporterMbs
dim f as FolderItem
f=SpecialFolder.Desktop.Child("rgb.jpg")
j.File=f
j.Mode=j.ModeRGB
j.Import
if j.Picture=nil and j.PictureData<>nil then
Canvas3.Backdrop=MemToRGBPicture(j.PictureData,j.Width,j.Height)
else
MsgBox "ModeRGB failed"
end if
End Sub
Sub testGrayPicture()
dim j as new JPEGImporterMbs
dim f as FolderItem
f=SpecialFolder.Desktop.Child("gray.jpg")
if not f.Exists then
MsgBox "We need a grayscale jpeg file named ""gray.jpg"" on your desktop folder."
quit
end if
j.File=f
j.Mode=j.ModePicture
j.Import
if j.Picture<>nil and j.PictureData=nil then
Canvas2.Backdrop=j.Picture
else
MsgBox "ModePicture gray failed"
end if
End Sub
Sub testPicture()
dim j as new JPEGImporterMbs
dim f as FolderItem
f=SpecialFolder.Desktop.Child("rgb.jpg")
if not f.Exists then
MsgBox "We need a RGB jpeg file named ""rgb.jpg"" on your desktop folder."
quit
end if
j.File=f
j.Mode=j.ModePicture
j.Import
if j.Picture<>nil and j.PictureData=nil then
Canvas1.Backdrop=j.Picture
else
MsgBox "ModePicture failed"
end if
End Sub
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
End Project
See also:
The items on this page are in the following plugins: MBS Images Plugin.