当前位置:网站首页>Unit screenshot saved on the phone
Unit screenshot saved on the phone
2022-06-30 04:42:00 【ToDoNothing】
Go straight to the code
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using UnityEngine.UI;
public class ScreenShot : MonoBehaviour
{
// This camera is used for screen capture , Camera's Claer Flags The attribute of is selected as Depth Only
public Camera CameraTrans;
private Texture2D mTexture1;
private string mPath;
public GameObject picture;
private string mingming;
// Use this for initialization
void Start()
{
CameraTrans = GameObject.FindGameObjectWithTag("ARCamera").GetComponent<Camera>();ji
}
// Update is called once per frame
void Update()
{
}
/// <summary>
/// Turn on the camera
/// </summary>
public void screenshot()
{
// Name with time
string mingming = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Day + System.DateTime.Now.Hour + System.DateTime.Now.Minute + System.DateTime.Now.Second;
// Platform judgment
if (Application.platform == RuntimePlatform.Android)
{
// Photo album path of Android device
mPath = "/sdcard/DCIM/Camera/" + mingming + ".jpg";
Debug.Log(mPath);
}
else if (Application.platform == RuntimePlatform.WindowsEditor)
{
mPath = Application.dataPath + "\\Resources\\" + mingming + ".jpg";
Debug.Log(mPath);
}
StartCoroutine(CaptureByCamera(CameraTrans, new Rect(0, 0, 1024, 768), mPath));
}
private IEnumerator CaptureByCamera(Camera mCamera, Rect mRect, string mFileName)
{
// Wait for the rendering thread to end
yield return new WaitForEndOfFrame();
// initialization RenderTexture
RenderTexture mRender = new RenderTexture((int)mRect.width, (int)mRect.height, 0);
// Set the render target of the camera
mCamera.targetTexture = mRender;
// Start rendering
mCamera.Render();
// Activate render map to read information
RenderTexture.active = mRender;
Texture2D mTexture = new Texture2D((int)mRect.width, (int)mRect.height, TextureFormat.RGB24, false);
// The screen pixel information is read and stored as texture data
mTexture.ReadPixels(mRect, 0, 0);
// application
mTexture.Apply();
// Release the camera , Destroy render maps
mCamera.targetTexture = null;
RenderTexture.active = null;
GameObject.Destroy(mRender);
// Encode the picture information into byte information
byte[] bytes = mTexture.EncodeToPNG();
// preservation
File.WriteAllBytes(mFileName, bytes);
// Store the texture map in the static class
mTexture1 = mTexture;
// picture.GetComponent<Image>().sprite = Sprite.Create(mTexture1, new Rect(0, 0, 1024, 768), new Vector2(Screen.height / 2, Screen.width / 2));
// If necessary, you can return to the screenshot
//return mTexture;
}
// Start is called before the first frame update
public void OnScreenShotClick()
{
//if (picture == null) return;
Debug.Log(" Screenshot ");
screenshot();
}
public void ScreenShotBtn()
{
//StartCoroutine(CaptureByRect());
}
}
边栏推荐
- 【Paper】2017_ Distributed control for high-speed trains movements
- Difference between request forwarding and redirection
- Webots notes day 2
- Static keyword
- Five methods to clear floating and their advantages and disadvantages
- 【Paper】2019_ Consensus Control of Multiple AUVs Recovery System Under Switching Topologies and Time D
- Circle center technology, very anxious?
- A virtual reality secret room escape adventure, let you see Technology Singapore
- SSL universal domain name certificate
- BeanFactory创建流程
猜你喜欢

Marvel fan welfare: Singapore Madame Tussauds Wax Museum Marvel 4D experience Museum

This connection is not a private connection this website may be pretending to steal your personal or financial information

How the FortiGate firewall rejects a port by using the local in policy policy

Redis实现短信登入功能(一)传统的Session登入

Use of thread pool

FortiGate firewall configuration log uploading regularly

【Paper】2021_ Observer-Based Controllers for Incrementally Quadratic Nonlinear Systems With Disturbanc

File system and directory operations

Universal Studios Singapore: a good place for a one-day parent-child tour in Singapore

Directory operations and virtual file systems
随机推荐
Royal Albert Hall, a popular landmark in London
FortiGate firewall modifies the default timeout of a session
Qt 6.3.1Conan软件包发布
FortiGate firewall quick initialization administrator password
Break through the existing customer group marketing, and try customer grouping management (including clustering model and other practical effect evaluation)
One interview question a day the difference between B tree and b+ tree
FortiGate firewall filters the specified session and cleans it up
QT creator 8 beta2 release
Threejs realizes the simulation of river, surface flow, pipe flow and sea surface
Websocket implementation principle
Difference between request forwarding and redirection
This connection is not a private connection this website may be pretending to steal your personal or financial information
Arrays class
Arsenal Stadium Tour - take you to the front and back of Arsenal Stadium
What to do when the alicloud SSL certificate expires
Geotrustov wildcard
SQL error caused by entity class: Oracle "ora-00904" error: possible case of invalid identifier
【Paper】2020_ Research on defense and evaluation strategy of heterogeneous UAV formation_ Zuojiankai
Qt6 QML Book/Qt Quick 3D/Qt Quick 3D
Qos(Quality of Service)