@MinDoc(copyright="Copyright 1998 - 2004, 2008, 2009, 20016 A. Weinert", author="Albrecht Weinert", version="V.44", lastModified="6.05.2021", usage="use instead of Image and for images", purpose="additional operations and information on images") public class ImageInfo extends Object implements Serializable, Paintable, Cloneable
img
,
getImg()
) and features additional information and
operations on it. The picture contained in and ImageInfo object is either
provided or made as a java.awt.Image
or preferably
as the more versatile
java.awt.image.BufferedImage
.imageSize(File)
to be used only if no further
informations or operations on the picture are required.ImageInfo
) can now be treated (serialised / de-serialised)
as all other function blocks.
(Image
is not serialisable by itself.).ImageInfo
with different sources for the picture are
comfortably supported.Modifier and Type | Class and Description |
---|---|
class |
ImageInfo.ImgDisplayer
The contained image as graphical component.
|
Modifier and Type | Field and Description |
---|---|
protected int |
h
The picture's dimension.
|
protected Image |
img
The Image.
|
protected int[] |
imgPixels
The picture as pixel array.
|
int |
leM
The left margin.
|
int |
loM
The lower margin.
|
int |
riM
The right margin.
|
int |
upM
The upper margin.
|
protected int |
w
The picture's dimension.
|
Modifier | Constructor and Description |
---|---|
protected |
ImageInfo()
No public Constructor.
|
Modifier and Type | Method and Description |
---|---|
Object |
clone()
Copy this object.
|
int |
gbDif(ImageInfo other)
Green + blue difference to other picture.
|
String |
getFName()
The picture's file name (if given).
|
Graphics |
getGraphics()
A Graphics object.
|
int |
getHeight()
The image's height.
|
Image |
getImg()
The Image.
|
static BufferedImage |
getImg(String fName)
Make an (buffered) Image by a file name.
|
int[] |
getImgPixels()
The image as pixel array.
|
static ImageInfo |
getInstance(Component comp)
Make an ImageInfo object by a graphical component.
|
static ImageInfo |
getInstance(File imgFile)
Make an ImageInfo object by a file.
|
static ImageInfo |
getInstance(InputStream ein,
String fName)
Make an ImageInfo object by a stream.
|
static ImageInfo |
getInstance(int[] imgPixels,
int w,
int h)
Make an ImageInfo object, empty or from memory content.
|
static ImageInfo |
getInstance(String fName)
Make an ImageInfo object by a file name.
|
static ImageInfo |
getInstance(String fName,
String ext,
Class<?> klass)
Make an ImageInfo object by a named file or class resource.
|
static ImageInfo |
getInstance(String fName,
String ext,
Prop prop)
Make an ImageInfo object by a named file or resource.
|
Dimension |
getSize()
The image's dimension.
|
int |
getWidth()
The image's width.
|
static String[] |
getWriterFormatNames()
The formats supported for writing.
|
static Dimension |
imageSize(File fi)
Determine the dimension of a .gif, .jpg or .png picture.
|
void |
paint(Graphics g,
int x,
int y,
int width,
int height)
The paint method.
|
BufferedImage |
scaleImage(Color bgColor,
int newWidth,
int newHeight)
Scaling an image.
|
BufferedImage |
surrondImage(Color bgColor,
int upM,
int loM,
int leM,
int riM)
Surround the picture with margins.
|
String |
toString()
State as text.
|
boolean |
writeImage(CharSequence formatName,
OutputStream output)
Writing the image to an output stream.
|
boolean |
writeImage(File imgFile)
Writing the image into a File.
|
boolean |
writeImage(String fileName)
Writing the image into a file named fileName.
|
protected transient volatile Image img
Image
itself
is not serialisable.protected volatile int w
protected volatile int h
protected volatile int[] imgPixels
getImgPixels()
public volatile int leM
surrondImage()
.leM
as well as
riM
, upM
and loM
are for informal reading
only. It's value has no effect in this class.public volatile int riM
leM
,
surrondImage()
public volatile int upM
leM
,
surrondImage()
public volatile int loM
leM
,
surrondImage()
protected ImageInfo()
public static Dimension imageSize(File fi)
file
. The file content should be one of the image formats
supplied by the underlying JDK / JRE installation. As standard
these are .gif., .jpg and .png. Additionally the file extension should
(with .gif must) comply with the image's type.fi
- the image filepublic final Image getImg()
java.awt.Image
or
preferably / most often a versatile
java.awt.image.BufferedImage
.public final String getFName()
public Object clone()
public static ImageInfo getInstance(File imgFile)
imgFile
- the filepublic static ImageInfo getInstance(String fName)
fName
- the file's namepublic static BufferedImage getImg(String fName)
fName
- the file's namepublic static ImageInfo getInstance(String fName, String ext, Class<?> klass)
ext
(if there and not
yet suffix of fName
).prop
is not null
Prop.getAsStream()
will be used
in trials to load the picture as resource.fName
- the name of the (image) filepublic static ImageInfo getInstance(String fName, String ext, Prop prop)
ext
(if there and not
yet suffix of fName
).prop
is not null
Prop.getAsStream()
will be used
in trials to load the picture as resource.fName
- the name of the (image) filepublic static ImageInfo getInstance(InputStream ein, String fName)
ein
- the streamfName
- name for the returned objectProp.getAsStream()
,
getInstance(String)
public static ImageInfo getInstance(Component comp)
getImg()
) is a
BufferedImage
of kind
BufferedImage
.TYPE_INT_ARGB
(4 Byte alpha RGB).comp
- the graphical component to catch; it has to be in a
renderable state.public static ImageInfo getInstance(int[] imgPixels, int w, int h)
getImg()
) is a
BufferedImage
of kind
BufferedImage
.TYPE_INT_ARGB
(4 Byte alpha RGB).imgPixels
- the pixel array (attention used / stored in the object
made as supplied reference; no copy made)w
- widthh
- heightpublic final int getWidth()
public final int getHeight()
public Dimension getSize()
Dimension
object for every call and is
only useful in cases where such an object is really required.getWidth()
and getHeight()
.public final int[] getImgPixels()
public int gbDif(ImageInfo other)
public Graphics getGraphics()
getImg()
), that provides a possibility to paint (on) it. It is
only returned if wrapped image is a BufferedImage. Otherwise null is
returned.surrondImage(..)
,
scaleImage(Color, int, int)
public BufferedImage surrondImage(Color bgColor, int upM, int loM, int leM, int riM)
img
) will be surrounded / enlarged by the
margins specified. The 3 * 8 bit colour model is used for the
operation.GrafHelper.surrondImage()
.surrondImage(null, -1,...)
will just change the
type of the wrapped image to BufferedImage, if possible and not yet
so.upM
, loM
, leM
and riM
.bgColor
- background respectively margin colour
(default ColorVal.ws
).upM
- upper margin in pixel (0..400).loM
- leM, riM the same for lower left and right.scaleImage(Color, int, int)
public BufferedImage scaleImage(Color bgColor, int newWidth, int newHeight)
img
) will be brought to the
specified size. The 3 * 8 bit colour model is used for the
operation.BufferedImage
it is returned as is.bgColor
- background colour (if not null)newHeight
- target heightnewWidth
- target widthsurrondImage(Color, int, int, int, int)
public boolean writeImage(CharSequence formatName, OutputStream output) throws IOException
surrondImage()
,
scaleImage(Color, int, int)
.formatName
- informal name of the image file / stream format
(default png)output
- the stream to write the image toIOException
- at problems with outputpublic static String[] getWriterFormatNames()
ComVar.NO_STRINGS
) is returned.writeImage()
public boolean writeImage(File imgFile) throws IOException
surrondImage()
,
scaleImage(Color, int, int)
.File
supplied. That will be overwritten with the picture
content. The file will be closed after successful writing.imgFile
- the file to write the image toIOException
- in case of file writing problemspublic boolean writeImage(String fileName) throws IOException
FileHelper
.getInstance(fileName))fileName
- the file to write the image toIOException
- in case of file output problemspublic void paint(Graphics g, int x, int y, int width, int height)
Paintable
orders this
ImageInfo
object to paint itself to a given location and a
given size.contract
.paint
in interface Paintable
g
- The notorious Graphics
object (that can
nowadays be expected to be a Graphics2D
).x
- y The left upper corner of where to paintwidth
- height The size of an surrounding rectangle to paint within