Basic Usage
Return Value
Thescreenshot() method returns raw PNG bytes:
Working with Screenshots
Save to File
Display with PIL/Pillow
Use with OpenCV
Send to Vision API
Working with Vision Model Coordinates
Different vision models and APIs return coordinates in different formats. TapKit’s geometry utilities help you convert between them:| Format | Range | Common in |
|---|---|---|
| Absolute pixels | 0 to width/height | Direct screen coordinates |
| Normalized | 0.0 to 1.0 | Many vision APIs |
| 0-1000 scale | 0 to 1000 | Lux, some UI detection models |
| Percentage | 0 to 100 | Some bounding box APIs |
Converting Model Output
Screenshot Loop
Capture screenshots at intervals:Client-Level Screenshots
You can also capture via the client directly:Performance Tips
Reduce capture frequency
Reduce capture frequency
Screenshots require a round-trip to the device. Capture only when needed rather than in a tight loop.
Process asynchronously
Process asynchronously
If doing heavy image processing, consider processing in a separate thread while capturing the next screenshot.
Use streaming for real-time
Use streaming for real-time
For real-time viewing, consider using TapKit’s WebRTC streaming instead of repeated screenshots.
Error Handling
- Phone not connected
- Mac app not running
- Request timeout