Java Reference
In-Depth Information
F
Loading the image ile
—inside the
impl_getPlatformPaint
function, the first
thing that is done is to load the image file. We use
ImageIO.read()
function
to read the image's content and return an instance of
java.awt.image.
BufferedImage
stored in variable
buff
.
F
Creating texture
—once the image is loaded, it is ready to be handed off to create
the
Paint
instance. This is done with an instance of the
TexturePaint
class. The
constructor of that class takes two arguments, including a
BufferedImage
, stored
in variable
buff
, and an instance of
Rectangle2D
, which provides the dimensions
of the image being loaded.
F
Using the paint
—the paint can be used wherever a Paint instance can be applied.
Here, we used the customized paint to fill an instance of the Circle shape:
Circle{...
fill:
CustomPaint{url:"{__DIR__}texture.png"} ...
}
When the texture paint is applied to a shape, it repeats the content of the image file across
the surface of the shape, where it is applied automatically.
The
{__DIR__}
built-in variable returns to the location where the
class being executed is found (in this case
source-code/src/
effects/
). This is covered in more detail in
Chapter 5
,
JavaFX Media
.
See also
F
Applying cool paint effects with gradients
Adding depth with lighting and shadow
effects
All of the shapes we have used so far have been rendered pretty bland with boring solid
colors. Let's say you want to enhance the look of your objects by adding depth for a more
engaging look. This recipe shows you how to use the
Effect
classes to add lighting and
shadow effects to visual nodes in the scene graph.
Getting ready
All Node instances can receive an effect through the
effect:Effect
property. You can
find all effects in the package
javafx.scene.effect
. For this recipe, we are going to
use effects classes
Lighting
,
DistantLighting
, and
DropShadow
.













