How to draw Image pattern with javaFX Canvas - java

I want to draw a repeating image on a javafx canvas, is there any way to do it other than manually reapeatedly drawing the same image over and over?

This can be done by setting the Paint for filling some area. A subclass of Paint is
https://openjfx.io/javadoc/12/javafx.graphics/javafx/scene/paint/ImagePattern.html
which does exactly what you want.

Related

Draw image as a polygon

I'm trying to draw an image as a polygon in Swing but I don't know how. Now I
only have code to draw filled polygon. This is not a cropped image, it is distorted.
What I need (Polygon with texture):
What I have - Filled polygon
gr.fillPolygon(x_points, y_points, points.length);
The easiest way to render 3D is using JOGL library which uses OpenGL to render in JPanel.

Android canvas, save/restore paint settings

I'm working with android canvas and sometimes the logic is like:
we have some settings in Paint object and draw some graphic using canvas
we should somehow save current Paint settings and draw another graphics
we should restore Paint settings to initial values and continue drawing
the problem is that I didn't find any convinient way to save/restore Paint settings.
I'm not sure that doing it manually is a good way. Could you please advise?
You should make as many paint objects as you need to paint draw on the canvas. You don't want to go changing them on the fly, they are only being used in draw which means you need them already having the value they need to paint. You restore and save on the canvas because that's just popping matrix off the stack, but, paints should be pre-established.

Draw transparent path

I'm developing a java application for draw through the drag of the mouse.
I need the JPanel to be transparent, but in this way lose the function rubber.
With the getBackground() can set the transparent color to use, but the path is not going to erase what was previously drawn.
Drawing with transparent means... drawing with transparent, so the previous color stays intact. What you want is clearing a part of the image (you're drawing on an image surface, right?). That can be done using the clearing rule of AlphaComposite.
// Assuming Graphics2D g, maybe from BufferedImage
g.setComposite(AlphaComposite.Clear);
// drawing now clears

With Java's graphics shape drawing operations, is there an easy way to give the shapes transparency gradients and blurry edges?

What I would like is to give circles a fill color with a gradient that starts from the middle and then as it moves out to the edges becomes progressively more transparent, giving a blur effect. What is the simplest way of doing this?
Try setting an appropiately defined java.awt.RadialGradientPaint (using Colors with alpha), then render your circles using that. You may need to translate the graphics coordinate system to get the gradient centered in the circle. (http://docs.oracle.com/javase/7/docs/api/java/awt/RadialGradientPaint.html)
Or just make an image in a graphics program and simply draw the image.

Rectangle fill using image

Using AWT, how do you import an image into a rectangle you have drawn? I want to assign the background to that particular rectangle only.
Set the Rectangle as the clipping region.
Draw the image at a point so (part of) it is inside the clipping region.
Clear the clip.
Draw the rectangle.
As seen in this answer (the shape here is of text, but same principle applies).
The most common approach is to override the the paint method in your component. Have a look at Graphics.drawImage(). Example: Drawing an Image
If you decide to move to Swing, you can take advantage of Swing's optimizied painting model, overriding paintComponent instead of paint.
See: Performing Custom Painting

Categories

Resources