Unloading images into files
To unload an image into a file, the unload:intoFileHandle:atOffset: message is sent to the appropriate CgImageFileFormat object. The method answers true if the image was successfully unloaded, or false if an error occurred. As with the load methods, the hasErrorOccurred, currentError, and currentErrorString methods can be used to handle errors.
Note:
Unloading does not modify the original object.
The following code unloads an image captured from the screen into a file named img-out.pcx using the PCX format:
| screen rect image file format success |
screen := CgScreen default.
rect := 0 @ 0 extent: screen width @ screen height.
image := screen rootWindow
getDeviceIndependentImage: rect.
format := CgPCXFileFormat new.
file := CfsFileDescriptor
open: 'img-out.pcx'
oflag: OCREAT | OTRUNC | OWRONLY.
success := format
unload: image
intoFileHandle: file atOffset: 0.
file close.
success
ifFalse: [self error: 'Error unloading image']
The unload:intoFile: method takes a file name as an argument. It creates the file if it does not exist, or overwrites the file if it does exist. The following code has the same effect as the previous example.
| screen rect image format |
screen := CgScreen default.
rect := 0 @ 0 extent: screen width @ screen height.
image := screen rootWindow
getDeviceIndependentImage: rect.
format := CgPCXFileFormat new.
(format unload: image intoFile: 'img-out.pcx')
ifFalse: [self error: 'Error unloading image']
Last modified date: 01/29/2015