Four ways to save picture as Tiff in Xojo

Depending on your needs, we can offer four different ways to save a picture in tiff (and other) formats.

NSImageMBS is a high level class for handling images on MacOS and it can save in various formats. CGImageDestinationMBS offers a way to export in something like 20 formats on MacOS and iOS (public.jpeg, public.png, com.compuserve.gif, public.tiff, public.jpeg-2000, com.apple.atx, org.khronos.ktx, org.khronos.astc, public.heic, com.microsoft.ico, com.microsoft.bmp, com.apple.icns, com.adobe.photoshop-image, com.adobe.pdf, com.truevision.tga-image, com.ilm.openexr-image, public.pbm, public.pvr).

For cross platform projects, you can for example try GMImageMBS class, which can write in over 100 formats. If you need tiff specific details, you may want to check our dedicated TiffPictureMBS class, which allows you to control all details and lets you set individual header fields.

[code]Dim p As Picture = LogoMBS(500)

// 1. NSImageMBS

Dim n As New NSImageMBS§
Dim tiff As String = n.TIFFRepresentation
Dim file1 As FolderItem = SpecialFolder.Desktop.Child(“test1.tif”)
Dim b As BinaryStream = BinaryStream.Create(file1)
b.Write tiff
b.Close

// 2. CGImageDestinationMBS

Dim image As CGImageMBS = CGImageMBS.CreateImage§
Dim file2 As FolderItem = SpecialFolder.Desktop.Child(“test2.tif”)
Dim dest As CGImageDestinationMBS = CGImageDestinationMBS.CreateWithFile(file2, “public.tiff”, 1)

dest.AddImage(image, Nil)

If dest.Finalize Then
// MsgBox “Saved”
Else
MsgBox “Failed to save.”
End If

// 3. GMImageMBS

Dim gmimage As New GMImageMBS§
Dim file3 As FolderItem = SpecialFolder.Desktop.Child(“test3.tif”)
gmimage.write(file3)

// 4. TiffPictureMBS

Dim t As New TiffPictureMBS
Dim file4 As FolderItem = SpecialFolder.Desktop.Child(“test4.tif”)

t.Pict = p

If t.Create(file4) Then
If t.WriteRGB Then
t.Close
// ok
Else
Break
End If
Else
Break
End If[/code]

Please do not hesitate to contact us with questions. And bring your projects with questions to the Xojo conferences to talk directly to us or Xojo engineers.

Here is the list of the GraphicsMagick codecs you can use to write:

  • 8BIM, Photoshop resource format
  • 8BIMTEXT, Photoshop resource text format
  • 8BIMWTEXT, Photoshop resource wide text format
  • APP1, Raw application information
  • APP1JPEG, Raw JPEG binary data
  • ART, PFS: 1st Publisher
  • AVS, AVS X image
  • B, Raw blue samples
  • BIGTIFF, Tagged Image File Format (64-bit offsets)
  • BMP, Microsoft Windows bitmap image
  • BMP2, Microsoft Windows bitmap image v2
  • BMP3, Microsoft Windows bitmap image v3
  • C, Raw cyan samples
  • CALS, Continuous Acquisition and Life-cycle Support Type 1 image
  • CIN, Cineon Image File
  • CMYK, Raw cyan, magenta, yellow, and black samples
  • CMYKA, Raw cyan, magenta, yellow, black, and opacity samples
  • DCX, ZSoft IBM PC multi-page Paintbrush
  • DPX, SMPTE 268M-2003 (DPX 2.0)
  • EPDF, Encapsulated Portable Document Format
  • EPI, Adobe Encapsulated PostScript Interchange format
  • EPS, Adobe Encapsulated PostScript
  • EPS2, Adobe Level II Encapsulated PostScript
  • EPS3, Adobe Level III Encapsulated PostScript
  • EPSF, Adobe Encapsulated PostScript
  • EPSI, Adobe Encapsulated PostScript Interchange format
  • EPT, Adobe Encapsulated PostScript with MS-DOS TIFF preview
  • EPT2, Adobe Level II Encapsulated PostScript with MS-DOS TIFF preview
  • EPT3, Adobe Level III Encapsulated PostScript with MS-DOS TIFF preview
  • EXIF, Exif digital camera binary data
  • FAX, Group 3 FAX (Not TIFF Group3 FAX!)
  • FITS, Flexible Image Transport System
  • G, Raw green samples
  • GIF, CompuServe graphics interchange format
  • GIF87, CompuServe graphics interchange format
  • GRAY, Raw gray samples
  • GRAYA, Raw gray samples + alpha
  • HISTOGRAM, Histogram of the image
  • HTML, Hypertext Markup Language and a client-side image map
  • ICB, Truevision Targa image
  • ICC, ICC Color Profile
  • ICM, ICC Color Profile
  • INFO, Image descriptive information and statistics
  • IPTC, IPTC Newsphoto
  • IPTCTEXT, IPTC Newsphoto text format
  • IPTCWTEXT, IPTC Newsphoto text format
  • J2C, JPEG-2000 Code Stream Syntax
  • JNG, JPEG Network Graphics
  • JP2, JPEG-2000 JP2 File Format Syntax
  • JPC, JPEG-2000 Code Stream Syntax
  • JPEG, Joint Photographic Experts Group JFIF format
  • JPG, Joint Photographic Experts Group JFIF format
  • K, Raw black samples
  • M, Raw magenta samples
  • M2V, MPEG Video Stream
  • MAP, Colormap intensities and indices
  • MAT, MATLAB Level 4.0-7.0 image formats
  • MATTE, MATTE raw opacity format
  • MIFF, Magick Image File Format
  • MNG, Multiple-image Network Graphics
  • MONO, Bi-level bitmap in least-significant-byte first order
  • MPC, Magick Persistent Cache image format
  • MPEG, MPEG Video Stream
  • MPG, MPEG Video Stream
  • MSL, Magick Scripting Language
  • MTV, MTV Raytracing image format
  • MVG, Magick Vector Graphics
  • NULL, Constant image of uniform color
  • O, Raw opacity samples
  • OTB, On-the-air bitmap
  • P7, Xv thumbnail format
  • PAL, 16bit/pixel interleaved YUV
  • PAM, Portable Arbitrary Map format
  • PBM, Portable bitmap format (black/white)
  • PCD, Photo CD
  • PCDS, Photo CD
  • PCL, Page Control Language
  • PCT, Apple Macintosh QuickDraw/PICT
  • PCX, ZSoft IBM PC Paintbrush
  • PDB, Palm Database ImageViewer Format
  • PDF, Portable Document Format
  • PGM, Portable graymap format (gray scale)
  • PGX, JPEG-2000 VM Format
  • PICON, Personal Icon
  • PICT, Apple Macintosh QuickDraw/PICT
  • PNG, Portable Network Graphics
  • PNG00, PNG that inherits type and depth from original
  • PNG24, 24-bit RGB PNG, opaque only
  • PNG32, 32-bit RGBA PNG, semitransparency OK
  • PNG48, opaque or binary transparent 48-bit RGB
  • PNG64, opaque or transparent 64-bit RGBA
  • PNG8, 8-bit indexed PNG, binary transparency only
  • PNM, Portable anymap
  • PPM, Portable pixmap format (color)
  • PREVIEW, Show a preview an image enhancement, effect, or f/x
  • PS, Adobe PostScript
  • PS2, Adobe Level II PostScript
  • PS3, Adobe Level III PostScript
  • PTIF, Pyramid encoded TIFF
  • R, Raw red samples
  • RAS, SUN Rasterfile
  • RGB, Raw red, green, and blue samples
  • RGBA, Raw red, green, blue, and matte samples
  • SGI, Irix RGB image
  • SHTML, Hypertext Markup Language and a client-side image map
  • SUN, SUN Rasterfile
  • TEXT, ASCII Text
  • TGA, Truevision Targa image
  • TIFF, Tagged Image File Format
  • TXT, ASCII Text
  • UIL, X-Motif UIL table
  • UYVY, 16bit/pixel interleaved YUV
  • VDA, Truevision Targa image
  • VICAR, VICAR rasterfile format
  • VID, Visual Image Directory
  • VIFF, Khoros Visualization image
  • VST, Truevision Targa image
  • WBMP, Wireless Bitmap (level 0) image
  • XBM, X Windows system bitmap (black/white)
  • XMP, Adobe XML metadata
  • XPM, X Windows system pixmap (color)
  • XV, Khoros Visualization image
  • Y, Raw yellow samples
  • YUV, CCIR 601 4:1:1 or 4:2:2 (8-bit only)

Either set Magick property directly or it’s detected by file extension on saving to a file.

Christian,

From the above seems you support write to mpg. Presumably this takes a series of images ?

I’d like to record the screen or a portion of it with more control than shelling out to ffmpeg…

This is just the list of coders, I exported.

To create video, you may check our JPEGMovieMBS class.
Or with AVFoundation the AVAssetWriterInputMBS and AVAssetWriterInputPixelBufferAdaptorMBS classes.

Thanks. Forget AV as an end format as it’s huge. Target is mp4.

I would usually just add images to movie and then later recompress it, when things are done.

Do you havecan example of recompression into mp4 Christian ?

see AVAssetExportSessionMBS class website.

There is even a list of examples on the bottom, you may want to check.

Will check it out thanks Christian.