Platforms to show: All Mac Windows Linux Cross-Platform
/GraphicsMagick/ImageMagick/ImageMagick Test Q16
Required plugins for this example: MBS GraphicsMagick Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /GraphicsMagick/ImageMagick/ImageMagick Test Q16
This example is the version from Thu, 6th Apr 2016.
Project "ImageMagick Test Q16.xojo_binary_project"
FileTypes
Filetype application/binary
End FileTypes
Class Window1 Inherits Window
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
Control StaticText3 Inherits Label
ControlInstance StaticText3 Inherits Label
End Control
Control StaticText4 Inherits Label
ControlInstance StaticText4 Inherits Label
End Control
Control StaticText5 Inherits Label
ControlInstance StaticText5 Inherits Label
End Control
Control ListBox1 Inherits ListBox
ControlInstance ListBox1 Inherits ListBox
End Control
EventHandler Sub Open()
const UndefinedFilter=0
const PointFilter=1
const BoxFilter=2
const TriangleFilter=3
const HermiteFilter=4
const HanningFilter=5
const HammingFilter=6
const BlackmanFilter=7
const GaussianFilter=8
const QuadraticFilter=9
const CubicFilter=10
const CatromFilter=11
const MitchellFilter=12
const LanczosFilter=13
const BesselFilter=14
const SincFilter=15
dim i as ImageMagickQ16MBS
dim image as IMImageQ16MBS
dim rimage as IMImageQ16MBS
dim image_info as IMImageInfoQ16MBS
dim s as string
dim f as FolderItem
dim linfo as IMMagickInfoListQ16MBS
dim minfo as IMMagickInfoQ16MBS
dim j,c as integer
dim b as BinaryStream
dim co as IMColorQ16MBS
i=new ImageMagickQ16MBS
LoadAPI i
i.InitializeMagick
StaticText1.text= i.HomeURL
StaticText2.text= i.ReleaseDate
StaticText3.text= i.Copyright
StaticText4.text= i.PackageName
StaticText5.text= i.QuantumDepth
linfo=i.MagickInfoList
if linfo<>Nil then
c=linfo.Count
for j=0 to c-1
minfo=linfo.Item(j)
ListBox1.AddRow minfo.Name
ListBox1.Cell(ListBox1.LastIndex,1)=minfo.Description
ListBox1.Cell(ListBox1.LastIndex,2)=minfo.Version
ListBox1.Cell(ListBox1.LastIndex,3)=minfo.ModuleName
next
end if
// Initialize the image info structure and read an image.
image_info=i.NewImageInfo
f=GetFolderItem("image.tiff")
if not f.Exists then
MsgBox "I need a file image.tiff in the project folder to scale it."
Return
end if
b=f.OpenAsBinaryFile(false)
s=b.Read(b.Length)
image_info.Filename="image.tiff"
image=i.ReadImageFromString(image_info,s)
if image = nil or Image.Handle = 0 then
MsgBox "Failed to load image."
Return
end if
if i.LastError<>0 then // An error? (0 for warning exceptions)
MsgBox i.LastException.Description+" "+i.LastException.Reason
Return
elseif image=nil then
MsgBox "Failed to load image."
Return
else
// Turn the images into a thumbnail sequence.
'rimage=image.Resize(100,80,LanczosFilter,1.0)
co=new IMColorQ16MBS(&cFF0000)
image.BackgroundColor=co
rimage=image.Rotate(50)
if i.LastError<>0 then
MsgBox i.LastException.Description
Return
elseif rimage=nil then
MsgBox "Failed to resize image."
Return
else
end if
image.DestroyImage
if rimage<>nil then
// Write the image as TIFF and destroy it.
s=rimage.ImageToBlob(image_info)
f=SpecialFolder.Desktop.Child("output.tiff")
b=f.CreateBinaryFile("application/binary")
b.Write s
b.Close
MsgBox "Saved "+f.Name+" on your desktop."
window2.Backdrop = rimage.CopyPicture(0,0,rimage.Width, rimage.Height)
rimage.DestroyImage
end if
end if
image_info.DestroyImageInfo
End EventHandler
Function FindFile(name as string) As FolderItem
// Look for file in parent folders from executable on
dim parent as FolderItem = app.ExecutableFile.Parent
while parent<>Nil
dim file as FolderItem = parent.Child(name)
if file<>Nil and file.Exists then
Return file
end if
parent = parent.Parent
wend
End Function
Sub LoadAPI(i as ImageMagickQ16MBS)
if TargetLinux then
if i.LoadLibrary("libMagick.so.6") then
//MsgBox "library loaded."
else
MsgBox "library failed."
Return
end if
elseif TargetWin32 then
// we go into the right folder, so ImageMagick finds it's DLLs.
dim folder as FolderItem = SpecialFolder.Applications.Child("ImageMagick-6.7.2-Q16")
if folder.Exists = false then
MsgBox "Please change path to ImageMagick folder in code."
break
Return
end if
if not ImageMagickQ16MBS.SetCurrentDirectory(folder) then
MsgBox "Failed to change working directory."
break
Return
end if
if i.LoadLibrary("CORE_RL_magick_.dll") then
//MsgBox "library loaded."
else
MsgBox "library failed."
Return
end if
else
// Mac OS X
dim f as FolderItem = FindFile("libMagickCore.2.dylib")
// set directory where lib is inside
call i.SetCurrentDirectory(f.parent)
// and load it
if i.LoadLibraryFile(f) then
//MsgBox "library loaded."
else
MsgBox "Library failed to load."+EndOfLine+EndOfLine+i.LoadErrorString
Return
// the library may depend on some other libraries like X11, so you need to have the other libaries, too.
end if
end if
End Sub
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
Class Window2 Inherits Window
End Class
End Project
The items on this page are in the following plugins: MBS GraphicsMagick Plugin.