Skip to content

Add Screenshot Capture API#5

Merged
great-majority merged 1 commit into
mainfrom
feat/screenshot
Jun 28, 2025
Merged

Add Screenshot Capture API#5
great-majority merged 1 commit into
mainfrom
feat/screenshot

Conversation

@great-majority

Copy link
Copy Markdown
Owner

This PR introduces a comprehensive screenshot capture system that allows external clients to capture the current Studio view as PNG images via WebSocket.

What's Added

📸 Screenshot Command

  • New screenshot command type - Capture current Studio view as PNG image
  • Flexible sizing options - Custom width/height or use optimized defaults
  • Transparency support - Optional alpha channel for advanced compositing
  • Capture mark control - Toggle Studio's capture overlay on/off
  • Base64 encoding - Images delivered as JSON-compatible Base64 strings

🔧 Technical Implementation

  • Native Studio integration - Uses Studio.GameScreenShot.CreatePngScreen() for high-quality captures
  • Multi-camera rendering - Leverages Studio's camera array for complete scene capture
  • Memory efficient - Automatic cleanup and resource management
  • Error handling - Comprehensive error reporting for failed captures

📏 Optimized Defaults

  • 480p default resolution (854x480) - Balanced quality vs. WebSocket size limits
  • ~50-100KB typical file sizes - Fits comfortably within WebSocket message limits
  • Instant capture - No file I/O, direct memory-to-network transmission

API Usage

// Simple capture (854x480)
{"type": "screenshot"}

// Custom size
{"type": "screenshot", "width": 1920, "height": 1080}

// Advanced options
{
  "type": "screenshot",
  "width": 854,
  "height": 480,
  "transparency": true,
  "mark": false
}

Response Format

{
  "type": "success",
  "message": "Screenshot captured successfully",
  "data": {
    "image": "iVBORw0KGgoAAAANSUhEUg...", // Base64 PNG data
    "width": 854,
    "height": 480,
    "format": "png",
    "transparency": false,
    "size": 67890
  }
}

Benefits

  • 🚀 Real-time monitoring - External tools can capture Studio state instantly
  • 📱 Remote preview - Build mobile/web interfaces showing current Studio view
  • 🎬 Automation workflows - Automated screenshot capture for documentation/testing
  • 🔄 Live streaming - Foundation for potential live streaming features
  • 💾 Memory efficient - No temporary files, direct network delivery

Documentation

  • Comprehensive examples - Both English and Japanese documentation
  • Parameter reference - Detailed explanation of all options
  • Error handling guide - Common issues and troubleshooting
  • Integration examples - Ready-to-use code snippets

This feature opens up new possibilities for external Studio integrations, from simple monitoring tools to sophisticated automation systems that need visual feedback from the
Studio environment.

- Implemented ScreenshotCommandHandler to process screenshot commands.
- Added logic to capture screenshots from the game and return them as Base64 encoded PNG images.
- Integrated the new command handler into the KKStudioSocketPlugin to handle incoming screenshot commands.
- Defined ScreenshotCommand class to encapsulate screenshot parameters such as width, height, transparency, and mark.
@great-majority great-majority self-assigned this Jun 28, 2025
@great-majority great-majority merged commit bc7862b into main Jun 28, 2025
3 checks passed
@great-majority great-majority deleted the feat/screenshot branch June 28, 2025 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant