java.lang.Object | |
↳ | android.graphics.Paint |
Known Direct Subclasses |
The Paint class holds the style and color information about how to draw geometries, text and bitmaps.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Paint.Align | Align specifies how drawText aligns its text relative to the [x,y] coordinates. | ||||||||||
Paint.Cap | The Cap specifies the treatment for the beginning and ending of stroked lines and paths. | ||||||||||
Paint.FontMetrics | Class that describes the various metrics for a font at a given text size. | ||||||||||
Paint.FontMetricsInt | Convenience method for callers that want to have FontMetrics values as integers. | ||||||||||
Paint.Join | The Join specifies the treatment where lines and curve segments join on a stroked path. | ||||||||||
Paint.Style | The Style specifies if the primitive being drawn is filled, stroked, or both (in the same color). |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | ANTI_ALIAS_FLAG | bit mask for the flag enabling antialiasing | |||||||||
int | DEV_KERN_TEXT_FLAG | bit mask for the flag enabling device kerning for text | |||||||||
int | DITHER_FLAG | bit mask for the flag enabling dithering | |||||||||
int | FAKE_BOLD_TEXT_FLAG | bit mask for the flag enabling fake-bold text | |||||||||
int | FILTER_BITMAP_FLAG | bit mask for the flag enabling bitmap filtering | |||||||||
int | LINEAR_TEXT_FLAG | bit mask for the flag enabling linear-text (no caching) | |||||||||
int | STRIKE_THRU_TEXT_FLAG | bit mask for the flag enabling strike-thru text | |||||||||
int | SUBPIXEL_TEXT_FLAG | bit mask for the flag enabling subpixel-text | |||||||||
int | UNDERLINE_TEXT_FLAG | bit mask for the flag enabling underline text |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a new paint with default settings.
| |||||||||||
Create a new paint with the specified flags.
| |||||||||||
Create a new paint, initialized with the attributes in the specified
paint parameter.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Return the distance above (negative) the baseline (ascent) based on the
current typeface and text size.
| |||||||||||
Measure the text, stopping early if the measured width exceeds maxWidth.
| |||||||||||
Measure the text, stopping early if the measured width exceeds maxWidth.
| |||||||||||
Measure the text, stopping early if the measured width exceeds maxWidth.
| |||||||||||
Clear the shadow layer.
| |||||||||||
Return the distance below (positive) the baseline (descent) based on the
current typeface and text size.
| |||||||||||
Helper to getColor() that just returns the color's alpha value.
| |||||||||||
Return the paint's color.
| |||||||||||
Get the paint's colorfilter (maybe be null).
| |||||||||||
Applies any/all effects (patheffect, stroking) to src, returning the
result in dst.
| |||||||||||
Return the paint's flags.
| |||||||||||
Return the font's recommended interline spacing, given the Paint's
settings for typeface, textSize, etc.
| |||||||||||
Allocates a new FontMetrics object, and then calls getFontMetrics(fm)
with it, returning the object.
| |||||||||||
Return the font's interline spacing, given the Paint's settings for
typeface, textSize, etc.
| |||||||||||
Return the recommend line spacing based on the current typeface and
text size.
| |||||||||||
Get the paint's maskfilter object.
| |||||||||||
Get the paint's patheffect object.
| |||||||||||
Get the paint's rasterizer (or null).
| |||||||||||
Get the paint's shader object.
| |||||||||||
Return the paint's Cap, controlling how the start and end of stroked
lines and paths are treated.
| |||||||||||
Return the paint's stroke join type.
| |||||||||||
Return the paint's stroke miter value.
| |||||||||||
Return the width for stroking.
| |||||||||||
Return the paint's style, used for controlling how primitives'
geometries are interpreted (except for drawBitmap, which always assumes
FILL_STYLE).
| |||||||||||
Return the paint's Align value for drawing text.
| |||||||||||
Return in bounds (allocated by the caller) the smallest rectangle that
encloses all of the characters, with an implied origin at (0,0).
| |||||||||||
Return in bounds (allocated by the caller) the smallest rectangle that
encloses all of the characters, with an implied origin at (0,0).
| |||||||||||
Return the path (outline) for the specified text.
| |||||||||||
Return the path (outline) for the specified text.
| |||||||||||
Return the paint's horizontal scale factor for text.
| |||||||||||
Return the paint's text size.
| |||||||||||
Return the paint's horizontal skew factor for text.
| |||||||||||
Return the advance widths for the characters in the string.
| |||||||||||
Return the advance widths for the characters in the string.
| |||||||||||
Return the advance widths for the characters in the string.
| |||||||||||
Return the advance widths for the characters in the string.
| |||||||||||
Get the paint's typeface object.
| |||||||||||
Get the paint's xfermode object.
| |||||||||||
Helper for getFlags(), returning true if ANTI_ALIAS_FLAG bit is set
AntiAliasing smooths out the edges of what is being drawn, but is has
no impact on the interior of the shape.
| |||||||||||
Helper for getFlags(), returning true if DITHER_FLAG bit is set
Dithering affects how colors that are higher precision than the device
are down-sampled.
| |||||||||||
Helper for getFlags(), returning true if FAKE_BOLD_TEXT_FLAG bit is set
| |||||||||||
Whether or not the bitmap filter is activated.
| |||||||||||
Helper for getFlags(), returning true if LINEAR_TEXT_FLAG bit is set
| |||||||||||
Helper for getFlags(), returning true if STRIKE_THRU_TEXT_FLAG bit is set
| |||||||||||
Helper for getFlags(), returning true if SUBPIXEL_TEXT_FLAG bit is set
| |||||||||||
Helper for getFlags(), returning true if UNDERLINE_TEXT_FLAG bit is set
| |||||||||||
Return the width of the text.
| |||||||||||
Return the width of the text.
| |||||||||||
Return the width of the text.
| |||||||||||
Return the width of the text.
| |||||||||||
Restores the paint to its default settings.
| |||||||||||
Copy the fields from src into this paint.
| |||||||||||
Helper to setColor(), that takes a,r,g,b and constructs the color int
| |||||||||||
Helper to setColor(), that only assigns the color's alpha value,
leaving its r,g,b values unchanged.
| |||||||||||
Helper for setFlags(), setting or clearing the ANTI_ALIAS_FLAG bit
AntiAliasing smooths out the edges of what is being drawn, but is has
no impact on the interior of the shape.
| |||||||||||
Set the paint's color.
| |||||||||||
Set or clear the paint's colorfilter, returning the parameter.
| |||||||||||
Helper for setFlags(), setting or clearing the DITHER_FLAG bit
Dithering affects how colors that are higher precision than the device
are down-sampled.
| |||||||||||
Helper for setFlags(), setting or clearing the FAKE_BOLD_TEXT_FLAG bit
| |||||||||||
Helper for setFlags(), setting or clearing the FILTER_BITMAP_FLAG bit.
| |||||||||||
Set the paint's flags.
| |||||||||||
Helper for setFlags(), setting or clearing the LINEAR_TEXT_FLAG bit
| |||||||||||
Set or clear the maskfilter object.
| |||||||||||
Set or clear the patheffect object.
| |||||||||||
Set or clear the rasterizer object.
| |||||||||||
Set or clear the shader object.
| |||||||||||
This draws a shadow layer below the main layer, with the specified
offset and color, and blur radius.
| |||||||||||
Helper for setFlags(), setting or clearing the STRIKE_THRU_TEXT_FLAG bit
| |||||||||||
Set the paint's Cap.
| |||||||||||
Set the paint's Join.
| |||||||||||
Set the paint's stroke miter value.
| |||||||||||
Set the width for stroking.
| |||||||||||
Set the paint's style, used for controlling how primitives'
geometries are interpreted (except for drawBitmap, which always assumes
Fill).
| |||||||||||
Helper for setFlags(), setting or clearing the SUBPIXEL_TEXT_FLAG bit
| |||||||||||
Set the paint's text alignment.
| |||||||||||
Set the paint's horizontal scale factor for text.
| |||||||||||
Set the paint's text size.
| |||||||||||
Set the paint's horizontal skew factor for text.
| |||||||||||
Set or clear the typeface object.
| |||||||||||
Helper for setFlags(), setting or clearing the UNDERLINE_TEXT_FLAG bit
| |||||||||||
Set or clear the xfermode object.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Called before the object's memory is reclaimed by the VM.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
bit mask for the flag enabling antialiasing
bit mask for the flag enabling device kerning for text
bit mask for the flag enabling dithering
bit mask for the flag enabling fake-bold text
bit mask for the flag enabling bitmap filtering
bit mask for the flag enabling linear-text (no caching)
bit mask for the flag enabling strike-thru text
bit mask for the flag enabling subpixel-text
bit mask for the flag enabling underline text
Create a new paint with the specified flags. Use setFlags() to change these after the paint is created.
flags | initial flag bits, as if they were passed via setFlags(). |
---|
Create a new paint, initialized with the attributes in the specified paint parameter.
paint | Existing paint used to initialized the attributes of the new paint. |
---|
Return the distance above (negative) the baseline (ascent) based on the current typeface and text size.
Measure the text, stopping early if the measured width exceeds maxWidth. Return the number of chars that were measured, and if measuredWidth is not null, return in it the actual width measured.
text | The text to measure |
---|---|
start | The offset into text to begin measuring at |
end | The end of the text slice to measure. |
measureForwards | If true, measure forwards, starting at start. Otherwise, measure backwards, starting with end. |
maxWidth | The maximum width to accumulate. |
measuredWidth | Optional. If not null, returns the actual width measured. |
Measure the text, stopping early if the measured width exceeds maxWidth. Return the number of chars that were measured, and if measuredWidth is not null, return in it the actual width measured.
text | The text to measure |
---|---|
measureForwards | If true, measure forwards, starting with the first character in the string. Otherwise, measure backwards, starting with the last character in the string. |
maxWidth | The maximum width to accumulate. |
measuredWidth | Optional. If not null, returns the actual width measured. |
Measure the text, stopping early if the measured width exceeds maxWidth. Return the number of chars that were measured, and if measuredWidth is not null, return in it the actual width measured.
text | The text to measure |
---|---|
index | The offset into text to begin measuring at |
count | The number of maximum number of entries to measure. If count is negative, then the characters before index are measured in reverse order. This allows for measuring the end of string. |
maxWidth | The maximum width to accumulate. |
measuredWidth | Optional. If not null, returns the actual width measured. |
Return the distance below (positive) the baseline (descent) based on the current typeface and text size.
Helper to getColor() that just returns the color's alpha value. This is the same as calling getColor() >>> 24. It always returns a value between 0 (completely transparent) and 255 (completely opaque).
Return the paint's color. Note that the color is a 32bit value containing alpha as well as r,g,b. This 32bit value is not premultiplied, meaning that its alpha can be any value, regardless of the values of r,g,b. See the Color class for more details.
Get the paint's colorfilter (maybe be null).
Applies any/all effects (patheffect, stroking) to src, returning the result in dst. The result is that drawing src with this paint will be the same as drawing dst with a default paint (at least from the geometric perspective).
src | input path |
---|---|
dst | output path (may be the same as src) |
Return the paint's flags. Use the Flag enum to test flag values.
Return the font's recommended interline spacing, given the Paint's settings for typeface, textSize, etc. If metrics is not null, return the fontmetric values in it.
metrics | If this object is not null, its fields are filled with the appropriate values given the paint's text attributes. |
---|
Allocates a new FontMetrics object, and then calls getFontMetrics(fm) with it, returning the object.
Return the font's interline spacing, given the Paint's settings for typeface, textSize, etc. If metrics is not null, return the fontmetric values in it. Note: all values have been converted to integers from floats, in such a way has to make the answers useful for both spacing and clipping. If you want more control over the rounding, call getFontMetrics().
Return the recommend line spacing based on the current typeface and text size.
Get the paint's maskfilter object.
Get the paint's patheffect object.
Get the paint's rasterizer (or null).
The raster controls/modifies how paths/text are turned into alpha masks.Get the paint's shader object.
Return the paint's Cap, controlling how the start and end of stroked lines and paths are treated.
Return the paint's stroke join type.
Return the paint's stroke miter value. Used to control the behavior of miter joins when the joins angle is sharp.
Return the width for stroking.
A value of 0 strokes in hairline mode. Hairlines always draws a single pixel independent of the canva's matrix.Return the paint's style, used for controlling how primitives' geometries are interpreted (except for drawBitmap, which always assumes FILL_STYLE).
Return the paint's Align value for drawing text. This controls how the text is positioned relative to its origin. LEFT align means that all of the text will be drawn to the right of its origin (i.e. the origin specifieds the LEFT edge of the text) and so on.
Return in bounds (allocated by the caller) the smallest rectangle that encloses all of the characters, with an implied origin at (0,0).
text | Array of chars to measure and return their unioned bounds |
---|---|
index | Index of the first char in the array to measure |
count | The number of chars, beginning at index, to measure |
bounds | Returns the unioned bounds of all the text. Must be allocated by the caller. |
Return in bounds (allocated by the caller) the smallest rectangle that encloses all of the characters, with an implied origin at (0,0).
text | String to measure and return its bounds |
---|---|
start | Index of the first char in the string to measure |
end | 1 past the last char in the string measure |
bounds | Returns the unioned bounds of all the text. Must be allocated by the caller. |
Return the path (outline) for the specified text. Note: just like Canvas.drawText, this will respect the Align setting in the paint.
text | The text to retrieve the path from |
---|---|
start | The first character in the text |
end | 1 past the last charcter in the text |
x | The x coordinate of the text's origin |
y | The y coordinate of the text's origin |
path | The path to receive the data describing the text. Must be allocated by the caller. |
Return the path (outline) for the specified text. Note: just like Canvas.drawText, this will respect the Align setting in the paint.
text | The text to retrieve the path from |
---|---|
index | The index of the first character in text |
count | The number of characterss starting with index |
x | The x coordinate of the text's origin |
y | The y coordinate of the text's origin |
path | The path to receive the data describing the text. Must be allocated by the caller. |
Return the paint's horizontal scale factor for text. The default value is 1.0.
Return the paint's text size.
Return the paint's horizontal skew factor for text. The default value is 0.
Return the advance widths for the characters in the string.
text | The text to measure |
---|---|
widths | array to receive the advance widths of the characters. Must be at least a large as the text. |
Return the advance widths for the characters in the string.
text | The text to measure |
---|---|
start | The index of the first char to to measure |
end | The end of the text slice to measure |
widths | array to receive the advance widths of the characters. Must be at least a large as (end - start). |
Return the advance widths for the characters in the string.
text | The text to measure |
---|---|
start | The index of the first char to to measure |
end | The end of the text slice to measure |
widths | array to receive the advance widths of the characters. Must be at least a large as the text. |
Return the advance widths for the characters in the string.
text | The text to measure |
---|---|
index | The index of the first char to to measure |
count | The number of chars starting with index to measure |
widths | array to receive the advance widths of the characters. Must be at least a large as count. |
Get the paint's typeface object.
The typeface object identifies which font to use when drawing or measuring text.Get the paint's xfermode object.
Helper for getFlags(), returning true if ANTI_ALIAS_FLAG bit is set AntiAliasing smooths out the edges of what is being drawn, but is has no impact on the interior of the shape. See setDither() and setFilterBitmap() to affect how colors are treated.
Helper for getFlags(), returning true if DITHER_FLAG bit is set Dithering affects how colors that are higher precision than the device are down-sampled. No dithering is generally faster, but higher precision colors are just truncated down (e.g. 8888 -> 565). Dithering tries to distribute the error inherent in this process, to reduce the visual artifacts.
Helper for getFlags(), returning true if FAKE_BOLD_TEXT_FLAG bit is set
Whether or not the bitmap filter is activated. Filtering affects the sampling of bitmaps when they are transformed. Filtering does not affect how the colors in the bitmap are converted into device pixels. That is dependent on dithering and xfermodes.
Helper for getFlags(), returning true if LINEAR_TEXT_FLAG bit is set
Helper for getFlags(), returning true if STRIKE_THRU_TEXT_FLAG bit is set
Helper for getFlags(), returning true if SUBPIXEL_TEXT_FLAG bit is set
Helper for getFlags(), returning true if UNDERLINE_TEXT_FLAG bit is set
Return the width of the text.
text | The text to measure |
---|
Return the width of the text.
text | The text to measure |
---|---|
start | The index of the first character to start measuring |
end | 1 beyond the index of the last character to measure |
Return the width of the text.
text | The text to measure |
---|---|
start | The index of the first character to start measuring |
end | 1 beyond the index of the last character to measure |
Return the width of the text.
text | The text to measure |
---|---|
index | The index of the first character to start measuring |
count | THe number of characters to measure, beginning with start |
Copy the fields from src into this paint. This is equivalent to calling get() on all of the src fields, and calling the corresponding set() methods on this.
Helper to setColor(), that takes a,r,g,b and constructs the color int
a | The new alpha component (0..255) of the paint's color. |
---|---|
r | The new red component (0..255) of the paint's color. |
g | The new green component (0..255) of the paint's color. |
b | The new blue component (0..255) of the paint's color. |
Helper to setColor(), that only assigns the color's alpha value, leaving its r,g,b values unchanged. Results are undefined if the alpha value is outside of the range [0..255]
a | set the alpha component [0..255] of the paint's color. |
---|
Helper for setFlags(), setting or clearing the ANTI_ALIAS_FLAG bit AntiAliasing smooths out the edges of what is being drawn, but is has no impact on the interior of the shape. See setDither() and setFilterBitmap() to affect how colors are treated.
aa | true to set the antialias bit in the flags, false to clear it |
---|
Set the paint's color. Note that the color is an int containing alpha as well as r,g,b. This 32bit value is not premultiplied, meaning that its alpha can be any value, regardless of the values of r,g,b. See the Color class for more details.
color | The new color (including alpha) to set in the paint. |
---|
Set or clear the paint's colorfilter, returning the parameter.
filter | May be null. The new filter to be installed in the paint |
---|
Helper for setFlags(), setting or clearing the DITHER_FLAG bit Dithering affects how colors that are higher precision than the device are down-sampled. No dithering is generally faster, but higher precision colors are just truncated down (e.g. 8888 -> 565). Dithering tries to distribute the error inherent in this process, to reduce the visual artifacts.
dither | true to set the dithering bit in flags, false to clear it |
---|
Helper for setFlags(), setting or clearing the FAKE_BOLD_TEXT_FLAG bit
fakeBoldText | true to set the fakeBoldText bit in the paint's flags, false to clear it. |
---|
Helper for setFlags(), setting or clearing the FILTER_BITMAP_FLAG bit. Filtering affects the sampling of bitmaps when they are transformed. Filtering does not affect how the colors in the bitmap are converted into device pixels. That is dependent on dithering and xfermodes.
filter | true to set the FILTER_BITMAP_FLAG bit in the paint's flags, false to clear it. |
---|
Set the paint's flags. Use the Flag enum to specific flag values.
flags | The new flag bits for the paint |
---|
Helper for setFlags(), setting or clearing the LINEAR_TEXT_FLAG bit
linearText | true to set the linearText bit in the paint's flags, false to clear it. |
---|
Set or clear the maskfilter object.
Pass null to clear any previous maskfilter. As a convenience, the parameter passed is also returned.maskfilter | May be null. The maskfilter to be installed in the paint |
---|
Set or clear the patheffect object.
Pass null to clear any previous patheffect. As a convenience, the parameter passed is also returned.effect | May be null. The patheffect to be installed in the paint |
---|
Set or clear the rasterizer object.
Pass null to clear any previous rasterizer. As a convenience, the parameter passed is also returned.rasterizer | May be null. The new rasterizer to be installed in the paint. |
---|
Set or clear the shader object.
Pass null to clear any previous shader. As a convenience, the parameter passed is also returned.shader | May be null. the new shader to be installed in the paint |
---|
This draws a shadow layer below the main layer, with the specified offset and color, and blur radius. If radius is 0, then the shadow layer is removed.
Helper for setFlags(), setting or clearing the STRIKE_THRU_TEXT_FLAG bit
strikeThruText | true to set the strikeThruText bit in the paint's flags, false to clear it. |
---|
Set the paint's Cap.
cap | set the paint's line cap style, used whenever the paint's style is Stroke or StrokeAndFill. |
---|
Set the paint's Join.
join | set the paint's Join, used whenever the paint's style is Stroke or StrokeAndFill. |
---|
Set the paint's stroke miter value. This is used to control the behavior of miter joins when the joins angle is sharp. This value must be >= 0.
miter | set the miter limit on the paint, used whenever the paint's style is Stroke or StrokeAndFill. |
---|
Set the width for stroking. Pass 0 to stroke in hairline mode. Hairlines always draws a single pixel independent of the canva's matrix.
width | set the paint's stroke width, used whenever the paint's style is Stroke or StrokeAndFill. |
---|
Set the paint's style, used for controlling how primitives' geometries are interpreted (except for drawBitmap, which always assumes Fill).
style | The new style to set in the paint |
---|
Helper for setFlags(), setting or clearing the SUBPIXEL_TEXT_FLAG bit
subpixelText | true to set the subpixelText bit in the paint's flags, false to clear it. |
---|
Set the paint's text alignment. This controls how the text is positioned relative to its origin. LEFT align means that all of the text will be drawn to the right of its origin (i.e. the origin specifieds the LEFT edge of the text) and so on.
align | set the paint's Align value for drawing text. |
---|
Set the paint's horizontal scale factor for text. The default value is 1.0. Values > 1.0 will stretch the text wider. Values < 1.0 will stretch the text narrower.
scaleX | set the paint's scale in X for drawing/measuring text. |
---|
Set the paint's text size. This value must be > 0
textSize | set the paint's text size. |
---|
Set the paint's horizontal skew factor for text. The default value is 0. For approximating oblique text, use values around -0.25.
skewX | set the paint's skew factor in X for drawing text. |
---|
Set or clear the typeface object.
Pass null to clear any previous typeface. As a convenience, the parameter passed is also returned.typeface | May be null. The typeface to be installed in the paint |
---|
Helper for setFlags(), setting or clearing the UNDERLINE_TEXT_FLAG bit
underlineText | true to set the underlineText bit in the paint's flags, false to clear it. |
---|
Set or clear the xfermode object.
Pass null to clear any previous xfermode. As a convenience, the parameter passed is also returned.xfermode | May be null. The xfermode to be installed in the paint |
---|
Called before the object's memory is reclaimed by the VM. This can only happen once the garbage collector has detected that the object is no longer reachable by any thread of the running application.
The method can be used to free system resources or perform other cleanup
before the object is garbage collected. The default implementation of the
method is empty, which is also expected by the VM, but subclasses can
override finalize()
as required. Uncaught exceptions which are
thrown during the execution of this method cause it to terminate
immediately but are otherwise ignored.
Note that the VM does guarantee that finalize()
is called at most
once for any object, but it doesn't guarantee when (if at all) finalize()
will be called. For example, object B's finalize()
can delay the execution of object A's finalize()
method and
therefore it can delay the reclamation of A's memory. To be safe, use a
ReferenceQueue
, because it provides more control
over the way the VM deals with references during garbage collection.
Throwable |
---|