https://github.com/alianblank/blankgalleryscreenshot
Unity 3D Gallery Screenshot
https://github.com/alianblank/blankgalleryscreenshot
Last synced: 3 months ago
JSON representation
Unity 3D Gallery Screenshot
- Host: GitHub
- URL: https://github.com/alianblank/blankgalleryscreenshot
- Owner: AlianBlank
- Created: 2016-10-17T05:29:02.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-13T10:14:47.000Z (over 7 years ago)
- Last Synced: 2025-02-28T17:12:39.831Z (4 months ago)
- Language: C#
- Size: 3.12 MB
- Stars: 6
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# BlankGalleryScreenshot
# Guide
## 在Android 上使用的时候必须在 清单文件中添加 下面的代码
```
```
# Demo
```
public class BlankGalleryScreenshotExample : MonoBehaviour
{
void OnGUI()
{
if (GUILayout.Button("Save", GUILayout.Width(200), GUILayout.Height(200)))
{
StartCoroutine(CaptureScreenshot());
}
if (GUILayout.Button("Save Image", GUILayout.Width(200), GUILayout.Height(200)))
{
if (!string.IsNullOrEmpty(imageFilePath))
{
BlankGalleryScreenshot.Instance.AddImageToGallery(imageFilePath);
}
}
if (GUILayout.Button("Copy Video", GUILayout.Width(200), GUILayout.Height(200)))
{
StartCoroutine(MoveVideo());
}
if (GUILayout.Button("Save Video", GUILayout.Width(200), GUILayout.Height(200)))
{
if (!string.IsNullOrEmpty(videoFilePath))
{
BlankGalleryScreenshot.Instance.AddVideoToGallery(videoFilePath);
}
}
}string videoFilePath;
private IEnumerator MoveVideo()
{
WWW www = new WWW(Application.streamingAssetsPath + "/videodemo.mp4");
yield return www;Debug.Log(www.error);
Debug.Log("read finsh");
videoFilePath = Application.persistentDataPath + "/videodemo.mp4";
Debug.Log(videoFilePath);
File.WriteAllBytes(videoFilePath, www.bytes);
www.Dispose();
}string imageFilePath;
private IEnumerator CaptureScreenshot()
{
yield return new WaitForEndOfFrame();Texture2D texture2D = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, true);
texture2D.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
texture2D.Apply();
imageFilePath = Application.persistentDataPath + "/" + DateTime.Now.ToFileTime() + ".jpg";
Debug.Log(imageFilePath);File.WriteAllBytes(imageFilePath, texture2D.EncodeToPNG());
Destroy(texture2D);
texture2D = null;
Resources.UnloadUnusedAssets();
GC.Collect();
BlankGalleryScreenshot.Instance.AddImageToGallery(imageFilePath);
}
}```