MCPcopy Create free account
hub / github.com/JetBrains/skija / drawBitmapCanvas

Method drawBitmapCanvas

examples/scenes/src/BitmapScene.java:82–117  ·  view source on GitHub ↗
(Canvas canvas, IRect target, float dpi)

Source from the content-addressed store, hash-verified

80 }
81
82 private void drawBitmapCanvas(Canvas canvas, IRect target, float dpi) {
83 try (var bitmap = new Bitmap();
84 var path = new Path();
85 var stroke = new Paint().setColor(0xFFe76f51).setMode(PaintMode.STROKE).setStrokeWidth(10);) {
86 bitmap.allocPixels(ImageInfo.makeS32((int) (target.getWidth() * dpi), (int) (target.getHeight() * dpi), ColorAlphaType.PREMUL));
87
88 bitmap.erase(0x80a8dadc);
89 int color = bitmap.getColor(10, 10);
90 assert 0x80a7d9db == color : "Expected 0x" + Integer.toString(0x80a7d9db, 16) + ", got 0x" + Integer.toString(color, 16);
91 float alpha = bitmap.getAlphaf(10, 10);
92 assert Math.abs(0.5f - alpha) < 0.01 : "Expected 0.5f, got " + alpha;
93
94 bitmap.erase(0x00FFFFFF, IRect.makeXYWH((int) ((target.getWidth() / 2 - 10) * dpi), (int) ((target.getHeight() / 2 - 10) * dpi), (int) (20 * dpi), (int) (20 * dpi)));
95 color = bitmap.getColor((int) (target.getWidth() / 2 * dpi), (int) (target.getHeight() / 2 * dpi));
96 assert 0x00000000 == color : "Expected 0x" + Integer.toString(0x00000000, 16) + ", got 0x" + Integer.toString(color, 16);
97 alpha = bitmap.getAlphaf((int) (target.getWidth() / 2 * dpi), (int) (target.getHeight() / 2 * dpi));
98 assert Math.abs(0f - alpha) < 0.01 : "Expected 0f, got " + alpha;
99
100 Canvas canvas2 = new Canvas(bitmap);
101 canvas2.scale(dpi, dpi);
102 path.moveTo(0, target.getHeight() / 2)
103 .lineTo(target.getWidth() / 2, target.getHeight() / 2 - target.getWidth() / 2)
104 .lineTo(target.getWidth(), target.getHeight() / 2)
105 .lineTo(target.getWidth() / 2, target.getHeight() / 2 + target.getWidth() / 2)
106 .closePath();
107 canvas2.drawPath(path, stroke);
108
109 try (Image image = Image.makeFromBitmap(bitmap.setImmutable())) {
110 canvas.drawImageRect(image, target.toRect());
111 }
112 }
113
114 try(var stroke = new Paint().setColor(0xFFE5E5E5).setMode(PaintMode.STROKE).setStrokeWidth(1);) {
115 canvas.drawRect(target.toRect(), stroke);
116 }
117 }
118
119 public void drawPixels(Canvas canvas, IRect target, IRect screen, float dpi) {
120 target = target.intersect(screen);

Callers 1

drawMethod · 0.95

Calls 15

makeS32Method · 0.95
makeXYWHMethod · 0.95
scaleMethod · 0.95
drawPathMethod · 0.95
makeFromBitmapMethod · 0.95
setStrokeWidthMethod · 0.80
setModeMethod · 0.80
allocPixelsMethod · 0.80
closePathMethod · 0.80
lineToMethod · 0.80
moveToMethod · 0.80
drawImageRectMethod · 0.80

Tested by

no test coverage detected