2024-03-30
This commit is contained in:
66
doc/31_painting.md
Normal file
66
doc/31_painting.md
Normal file
@@ -0,0 +1,66 @@
|
||||
# Painting
|
||||
|
||||
```java
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
final Graphics2D graphics2D = (Graphics2D) g;
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
* `component.paint(Graphics)`
|
||||
* `paintComponent(Graphics)` -> `paintBorder(Graphics)` -> `paintChildren(Graphics)`
|
||||
|
||||
|
||||
## Graphics2D
|
||||
|
||||
|
||||
* `drawString()`
|
||||
* `drawImage()`
|
||||
* `drawLine()`
|
||||
* `drawArc()` / `drawRect()` / `drawOval()` / `drawPolygon()`
|
||||
* `draw()`
|
||||
* `fillArc()` / `fillRect()` / `fillOval()` / `fillPolygon()`
|
||||
* `fill()`
|
||||
|
||||
* `rotate()`
|
||||
* `scale()`
|
||||
* `shear()`
|
||||
* `translate()`
|
||||
|
||||
### Stroke
|
||||
|
||||
```java
|
||||
import java.awt.*;
|
||||
|
||||
Graphics2D graphics2D = (Graphics2D) g;
|
||||
BasicStroke stroke = new BasicStroke(1.f,BasicStroke.CAP_BUTT,BasicStroke.JOIN_MITER,10.f,{10.f},0.f);
|
||||
graphics2D.setStroke(stroke);
|
||||
```
|
||||
#### Join style
|
||||
* JOIN_BEVEL
|
||||
* JOIN_MITER
|
||||
* JOIN_ROUND
|
||||
|
||||
#### End-cap style
|
||||
* CAP_BUTT
|
||||
* CAP_ROUND
|
||||
* CAP_SQUARE
|
||||
|
||||
### Paint
|
||||
* `Color`, `GradientPaint`, `TexturePaint`
|
||||
|
||||
```java
|
||||
import java.awt.*;
|
||||
|
||||
Paint paint = new GradientPaint(x1,y1,color1,x2,y2,color2);
|
||||
graphics2D.setPaint(paint);
|
||||
```
|
||||
|
||||
|
||||
### AffineTransform
|
||||
|
||||
* `AffineTransform.getRotateTransform()`
|
||||
* `AffineTransform.getScaleTransform()`
|
||||
* `AffineTransform.getShearTransform()`
|
||||
* `AffineTransform.getTranslateTransform()`
|
||||
Reference in New Issue
Block a user