Skip to content
Snippets Groups Projects
Commit 4741d47a authored by unknown's avatar unknown
Browse files

s

s
:
with '#' will be ignored, and an empty message aborts the commit.
parent ff31b909
No related branches found
No related tags found
No related merge requests found
Showing
with 0 additions and 70 deletions
using UnityEngine;
public class ScreenShot : MonoBehaviour
{
public Camera captureCamera; // Assign ;your camera in the Unity Inspector
public float ScreenShotDelay;
public float ScreenShotTimer;
public string savePath = ".png"; // Specify the save path and file name
public string saveDir = "C:\\Users\\copom\\Artificial_Hunter_Vision\\TestImgSet_NO_LIGHT\\";
public void Start(){
ScreenShotDelay = 1;
ScreenShotTimer = 0;
}
private void Update()
{
ScreenShotTimer += Time.deltaTime;
// Check for user input to trigger the capture (e.g., a key press)
if (ScreenShotTimer > ScreenShotDelay)
{
ScreenShotTimer = 0;
CaptureAndSaveImage();
}
}
private void CaptureAndSaveImage()
{
// Ensure the captureCamera is not null
if (captureCamera == null)
{
Debug.LogError("Capture Camera is not assigned!");
return;
}
// Create a RenderTexture to capture the camera's output
RenderTexture renderTexture = new RenderTexture(Screen.width, Screen.height, 24);
captureCamera.targetTexture = renderTexture;
// Render the camera's view into the RenderTexture
captureCamera.Render();
// Create a Texture2D and read the pixels from the RenderTexture
Texture2D screenShot = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
RenderTexture.active = renderTexture;
screenShot.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
screenShot.Apply();
// Save the captured image to a file
byte[] bytes = screenShot.EncodeToPNG();
System.IO.File.WriteAllBytes(saveDir + Random.Range(0, 10000) + savePath, bytes);
// Clean up resources
RenderTexture.active = null;
captureCamera.targetTexture = null;
Destroy(renderTexture);
Debug.Log("Image captured and saved to " + savePath);
}
}
fileFormatVersion: 2
guid: aec4edb0bd9d6634c885bca573a42696
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Unity/ImgDataset/1009CapturedImage.png

44.8 KiB

Unity/ImgDataset/1017CapturedImage.png

11.1 KiB

Unity/ImgDataset/1052CapturedImage.png

19.7 KiB

Unity/ImgDataset/1058CapturedImage.png

27 KiB

Unity/ImgDataset/1066CapturedImage.png

57.2 KiB

Unity/ImgDataset/108CapturedImage.png

65.1 KiB

Unity/ImgDataset/1091CapturedImage.png

30.5 KiB

Unity/ImgDataset/1107CapturedImage.png

28.5 KiB

Unity/ImgDataset/1113CapturedImage.png

87.4 KiB

Unity/ImgDataset/1126CapturedImage.png

15.5 KiB

Unity/ImgDataset/1130CapturedImage.png

44.5 KiB

Unity/ImgDataset/1134CapturedImage.png

18.8 KiB

Unity/ImgDataset/1167CapturedImage.png

27.8 KiB

Unity/ImgDataset/1171CapturedImage.png

90 KiB

Unity/ImgDataset/117CapturedImage.png

67.9 KiB

Unity/ImgDataset/1212CapturedImage.png

67.2 KiB

Unity/ImgDataset/1229CapturedImage.png

27.6 KiB

Unity/ImgDataset/1230CapturedImage.png

17.2 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment