|
Class: XBMReader
Object
|
+--ImageReader
|
+--XBMReader
- Package:
- stx:libview2
- Category:
- Graphics-Images-Readers
- Version:
- rev:
1.67
date: 2023/10/12 16:16:38
- user: stefan
- file: XBMReader.st directory: libview2
- module: stx stc-classLibrary: libview2
this class provides methods for loading and saving x-bitmap-file images.
These images can (for example) be created using the bitmap editor supplied
with X.
Only monochrome images can be represented in this format.
Both reading and writing of images is supported.
copyrightCOPYRIGHT (c) 1992 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
class initialization
-
initialize
-
tell Image-class, that a new fileReader is present
for the '.xbm' extension.
testing
-
canRepresent: anImage
-
return true, if anImage can be represented in my file format
-
isValidImageStream: inStream
-
return true, if inStream possibly contains a XBM image.
The stream is left open and position undefined afterwards
private-reading
-
extractValueFor: keyword fromLine: lineString
-
reading
-
fromStream: aStream
-
read an image in xbm format from aStream.
Leave image description in instance variables.
(i.e. to get the image, ask with image).
writing
-
save: image onStream: aStream
-
save image as XBM cdata on aStream.
Only depth1 b&w images can be represented in this format.
Usage example(s):
|file original restored|
original := Image fromFile:'../../goodies/bitmaps/xbmBitmaps/TicTacToe.xbm'.
file := String streamContents:[:stream |
XBMReader save:original onStream:stream
].
restored := XBMReader fromStream:(file readStream).
self assert:(restored = original)
|
Reading from a file:
|image|
image := Image fromFile:('../../goodies/bitmaps/xbmBitmaps/TicTacToe.xbm').
image inspect
|
Saving to a file:
|image|
image := Image fromScreen:(0@0 corner:30@30).
image := image asThresholdMonochromeImage.
XBMReader save:image onFile:'/tmp/test.xbm'.
'/tmp/test.xbm' asFilename contents asString inspect.
(Image fromFile:('/tmp/test.xbm')) inspect.
|
Or directly into a stream:
|image stream|
image := Image fromScreen:(0@0 corner:30@30).
image := image asThresholdMonochromeImage.
stream := WriteStream on:(String new).
XPMReader save:image onStream:stream.
stream contents inspect.
|
|