Add JPEG format support in take screenshot#187
Merged
nowsprinting merged 4 commits intomasterfrom Mar 1, 2026
Merged
Conversation
Add ImageFormat enum (Png/Jpeg), TakeScreenshotAsJpegBytesAsync stub, extend TakeScreenshotAsync with format/quality params, and update GetSavePath to accept extension as parameter. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Use AsyncGPUReadback path with ImageConversion.EncodeArrayToJPG when supported, falling back to EncodeToJPG for other platforms. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…eScreenPixelsAsync Deduplicate ~35 lines of identical screen capture logic (camera setup, EndOfFrameAsync, RenderTexture capture, GPU readback, thread switching) shared between TakeScreenshotAsPngBytesAsync and TakeScreenshotAsJpegBytesAsync. Replace fragile format.ToString().ToLower() with an explicit GetFileExtension switch. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds JPEG encoding support to the runtime ScreenshotHelper API (primarily for the async/Awaitable screenshot path) and expands the test suite to cover JPEG output.
Changes:
- Added
ImageFormatenum to represent screenshot encoding formats (PNG/JPEG). - Extended
ScreenshotHelper.TakeScreenshotAsyncto support JPEG output (with configurable JPEG quality) and choose the correct output extension. - Added new runtime tests for JPEG byte capture and JPEG file output/extension behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| Tests/RuntimeInternals/ScreenshotHelperTest.cs | Adds tests for JPEG byte output and JPEG file saving/extension behavior. |
| RuntimeInternals/ScreenshotHelper.cs | Implements JPEG encoding path, refactors pixel capture to share between PNG/JPEG, and updates save-path extension handling. |
| RuntimeInternals/ImageFormat.cs | Introduces ImageFormat enum (Png/Jpeg) used by the screenshot API. |
| RuntimeInternals/ImageFormat.cs.meta | Unity meta file for the new ImageFormat.cs asset. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This comment has been minimized.
This comment has been minimized.
- Fix XML doc for `filename` param of `TakeScreenshotAsync`: extension depends on `format` parameter, not always ".png" - Use `ToLowerInvariant()` instead of `ToLower()` in `GetFileExtension` to avoid locale-dependent behavior for file extensions - Add `TakeScreenshotAsync_WithJpegFormat_SaveToDefaultPath` test to cover the case where filename is omitted with JPEG format Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Code Metrics Report
Details | | master (8806ff3) | #187 (4531665) | +/- |
|---------------------|------------------|----------------|-------|
+ | Coverage | 80.2% | 80.4% | +0.1% |
| Files | 45 | 45 | 0 |
| Lines | 1663 | 1695 | +32 |
+ | Covered | 1335 | 1363 | +28 |
+ | Code to Test Ratio | 1:1.0 | 1:1.0 | +0.0 |
| Code | 2917 | 2979 | +62 |
+ | Test | 3077 | 3149 | +72 |
+ | Test Execution Time | 5m47s | 5m44s | -3s |Code coverage of files in pull request scope (90.6% → 89.8%)
Reported by octocov |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds JPEG encoding support to the async screenshot API (
TakeScreenshotAsyncand related methods).Changes
New API
TakeScreenshotAsJpegBytesAsync(float scale, int quality)— captures and returns a JPEG-encoded byte array with configurable quality (1–100, default 75)TakeScreenshotAsync— newformatandqualityparameters for JPEG output; file extension is automatically set to.jpegwhenformat: ImageFormat.JpegRefactoring
CaptureScreenPixelsAsync, used by bothTakeScreenshotAsPngBytesAsyncand the newTakeScreenshotAsJpegBytesAsyncGetFileExtension(ImageFormat)helper to resolve format-dependent file extensionsGetSavePathto accept an explicitextensionargument (previously hardcoded to"png")Fixes
filenameparameter ofTakeScreenshotAsync: the default filename extension now correctly reflects theformatparameter instead of hardcoding.pngformat.ToString().ToLower()toToLowerInvariant()inGetFileExtensionto avoid locale-dependent behavior for file extensionsTests
TakeScreenshotAsJpegBytesAsync_ReturnsJpegBytes— verifies JPEG output dimensionsTakeScreenshotAsync_WithJpegFormat_SavesJpegFile— parameterized over quality values[1, 50, 100]TakeScreenshotAsync_WithJpegFormatAndFilename_SavesWithJpegExtension— verifies.jpegextension is appended when omittedTakeScreenshotAsync_WithJpegFormatAndJpegFilename_DoesNotDuplicateExtension— verifies no.jpeg.jpegdouble extensionTakeScreenshotAsync_WithJpegFormat_SaveToDefaultPath— verifies default save path uses.jpegextension when no filename is providedNotes
TakeScreenshot) andTakeScreenshotAttributeis unchanged and continues to save PNG onlySystemInfo.supportsAsyncGPUReadbackis false, thescaleparameter is ignored in the fallback path (pre-existing behavior, tracked separately)