Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class Picture
- Object
- Picture
An immutable picture block: the original encoded image bytes, kept as they were read so a
document written back carries the same image, plus its displayed size in points.
Fields
public final String id | The block id. |
public final String mimeType | The MIME type of data(), such as image/png; empty for a linked picture. |
public final String source | The URL a linked picture names, as Markdown’s  or HTML’s <img src> gives it; null for a picture that holds its own bytes. |
public final float width | The displayed width in points. |
public final float height | The displayed height in points. |
public final String description | Alternative text for readers that cannot show the picture. |
public static final String INLINE = "inline" | Laid out in the line like a large character; the default. |
public static final String SQUARE = "square" | Floats at a side of the column; text wraps around its box. |
public static final String TOP_BOTTOM = "topAndBottom" | Floats on lines of its own; no text beside it. |
public static final String BEHIND = "behind" | Floats behind the text, which ignores it. |
public static final String IN_FRONT = "inFront" | Floats over the text, which ignores it. |
public static final String LEFT = "left" | Horizontal placement of a floating picture: at the left edge of the column. |
public static final String CENTER = "center" | Horizontal placement of a floating picture: centered in the column. |
public static final String RIGHT = "right" | Horizontal placement of a floating picture: at the right edge of the column. |
public final String wrap | How text flows around the picture: INLINE, SQUARE, TOP_BOTTOM, BEHIND or IN_FRONT. |
public final String align | Where a floating picture sits across the column: LEFT, CENTER or RIGHT. |
public final float offsetY | How far below the top of its anchor paragraph a floating picture starts, in points. |
public final float distance | The gap kept between a floating picture and the text wrapped around it, in points. |
Constructors
public Picture(String id, byte[] data, String mimeType, float width, float height, String description) | Creates a picture. |
Methods
public static Picture linked(String id, String source, float width, float height, String description) | A picture that names its image by URL instead of holding it. |
public boolean isLinked() | Whether the picture names its image by URL and holds no bytes. |
public boolean isFloating() | Whether the picture floats instead of sitting in a line. |
public Picture withWrap(String wrapMode, String alignment, float offset, float gap) | A copy placed differently. |
public String id() | The block id. |
public byte[] data() | The encoded image. |
public int dataLength() | The size of the encoded image. |
public Picture withSize(float w, float h) | A copy shown at another size. |
public boolean equals(Object o) | Two pictures are equal when their id, bytes, source, type, size, description and placement are. |
public int hashCode() | A hash consistent with equals. |
public String displayText() | A picture in a line reads as nothing in plain text. |
Inherited methods
Field details
id
public final String idThe block id.
mimeType
public final String mimeTypeThe MIME type of
data(), such as image/png; empty for a linked picture.source
public final String sourceThe URL a linked picture names, as Markdown’s
 or HTML’s <img src>
gives it; null for a picture that holds its own bytes. A linked picture has no bytes:
HTML, Markdown and .cn1doc write the URL back, while DOCX, ODT, RTF, a page view and
PDF export, which can only show an image they hold, leave its box empty or skip it.width
public final float widthThe displayed width in points.
height
public final float heightThe displayed height in points.
description
public final String descriptionAlternative text for readers that cannot show the picture.
INLINE
public static final String INLINE = "inline"Laid out in the line like a large character; the default.
SQUARE
public static final String SQUARE = "square"Floats at a side of the column; text wraps around its box.
TOP_BOTTOM
public static final String TOP_BOTTOM = "topAndBottom"Floats on lines of its own; no text beside it.
BEHIND
public static final String BEHIND = "behind"Floats behind the text, which ignores it.
IN_FRONT
public static final String IN_FRONT = "inFront"Floats over the text, which ignores it.
LEFT
public static final String LEFT = "left"Horizontal placement of a floating picture: at the left edge of the column.
CENTER
public static final String CENTER = "center"Horizontal placement of a floating picture: centered in the column.
RIGHT
public static final String RIGHT = "right"Horizontal placement of a floating picture: at the right edge of the column.
wrap
public final String wrapHow text flows around the picture:
INLINE, SQUARE, TOP_BOTTOM, BEHIND or
IN_FRONT.align
public final String alignWhere a floating picture sits across the column:
LEFT, CENTER or RIGHT.offsetY
public final float offsetYHow far below the top of its anchor paragraph a floating picture starts, in points.
distance
public final float distanceThe gap kept between a floating picture and the text wrapped around it, in points.
Constructor details
Picture
public Picture(String id, byte[] data, String mimeType, float width, float height, String description)Creates a picture.
Parameters
idString- the block id
databyte[]- the encoded image; the array is copied
mimeTypeString- its MIME type
widthfloat- the displayed width in points, greater than zero
heightfloat- the displayed height in points, greater than zero
descriptionString- alternative text, or null
Method details
linked
public static Picture linked(String id, String source, float width, float height, String description)A picture that names its image by URL instead of holding it.
Parameters
idString- the block id
sourceString- the image URL, not empty
widthfloat- the displayed width in points, greater than zero
heightfloat- the displayed height in points, greater than zero
descriptionString- alternative text, or null
Returns
the picture
isLinked
public boolean isLinked()Whether the picture names its image by URL and holds no bytes.
Returns
true when
source is setisFloating
public boolean isFloating()Whether the picture floats instead of sitting in a line.
Returns
true unless the wrap is
INLINEwithWrap
public Picture withWrap(String wrapMode, String alignment, float offset, float gap)A copy placed differently.
Parameters
wrapModeStringINLINE,SQUARE,TOP_BOTTOM,BEHINDorIN_FRONTalignmentStringLEFT,CENTERorRIGHToffsetfloat- points below the top of the anchor paragraph
gapfloat- points kept between the picture and wrapped text, 0 to 72
Returns
the copy
id
public String id()The block id.
Returns
the id
data
public byte[] data()The encoded image.
Returns
a copy of the bytes; empty for a linked picture
dataLength
public int dataLength()The size of the encoded image.
Returns
the byte count
withSize
public Picture withSize(float w, float h)A copy shown at another size.
Parameters
wfloat- the width in points
hfloat- the height in points
Returns
the copy
equals
public boolean equals(Object o)Two pictures are equal when their id, bytes, source, type, size, description and placement
are.
Parameters
oObject- the other object
Returns
true when equal
hashCode
public int hashCode()A hash consistent with
equals.Returns
the hash
displayText
public String displayText()A picture in a line reads as nothing in plain text.
Returns
the empty string