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