资源简介
直接调用:ScreenshotHelper.iCaptureScreen(CaptureScreenCallBack);即可实现截屏。
函数void CaptureScreenCallBack(Texture2D texture2D)
{
new FilePathName().SaveTextureAs(texture2D,FilePathName.SaveFormat.JPG);
}
是截屏成功后的回调函数,负责保存图片。
简单易用!经测试,无问题!
代码片段和文件信息
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.IO;
public class FilePathName
{
public enum SaveFormat
{
GIF = 0
JPG
PNG
}
public string GetSaveDirectory()
{
//GIF store in Virtual Memory
//Available path: Application.persistentDataPath Application.temporaryCachePath Application.dataPath
//Do not allow sub-Folder under the path. If you need to view gif you can filter the file names to include .gif only.
#if UNITY_EDITOR
return Application.dataPath;
#else
// return Application.persistentDataPath;
return “/storage/emulated/0/DCIM/“;
#endif
}
public string GeFileNameWithoutExt()
{
return DateTime.Now.ToString(“yyyy-MM-dd-HH-mm-ss“);
}
public string GetGifFileName()
{
string timestamp = GeFileNameWithoutExt();
return “GIF_“ + timestamp;
}
public string GetGifFullPath()
{
return GetSaveDirectory() + “/“ + GetGifFileName() + “.gif“;
}
public string GetDownloadedGifSaveFullPath()
{
return GetSaveDirectory() + “/“ + GetGifFileName() + “.gif“;
}
public string GetJpgFileName()
{
string timestamp = GeFileNameWithoutExt();
return “JPG_“ + timestamp;
}
public string GetJpgFullPath()
{
return GetSaveDirectory() + “/“ + GetJpgFileName() + “.jpg“;
}
public string GetPngFileName()
{
string timestamp = GeFileNameWithoutExt();
return “PNG_“ + timestamp;
}
public string GetPngFullPath()
{
return GetSaveDirectory() + “/“ + GetPngFileName() + “.png“;
}
public byte[] ReadFileToBytes(string fullPath)
{
return File.ReadAllBytes(fullPath);
}
public void WriteBytesToFile(string toFullpath byte[] byteArray)
{
File.WriteAllBytes(toFullpath byteArray);
}
public void FileStreamTo(string fullpath byte[] byteArray)
{
using( FileStream fs = new FileStream(fullpath FileMode.Create FileAccess.Write) )
{
fs.Write(byteArray 0 byteArray.Length);
}
}
public string SaveTextureAs(Texture2D texture2D SaveFormat format = SaveFormat.JPG)
{
string savePath = string.Empty;
switch(format)
{
case SaveFormat.JPG:
savePath = GetJpgFullPath ();
Debug.Log (“savePath is: “+savePath);
WriteBytesToFile(savePath texture2D.EncodeToJPG(90));
break;
case SaveFormat.PNG:
savePath = GetPngFullPath();
WriteBytesToFile(savePath texture2D.EncodeToPNG());
break;
case SaveFormat.GIF:
//savePath = ProGifTexture2DsToGIF.Instance.Save(new List{texture2D} texture2D.width texture2D.height 1 0 10);
break;
}
return savePath;
}
// public string SaveTexturesAsGIF(List textureList int width int height int fps int loop int quality
// Action onFileSaved = null Action onFileSaveProgress = null
// ProGifTexture2DsToGIF.ResolutionHandle resolutionHandle = ProGifTexture2DsToGIF.ResolutionHandle.ResizeKeepRatio)
// {
// return ProGifTexture2DsToGIF.Instance.Save(textureList width height fps loop quality onFileSaved onFileSaveProgress
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 117072 2017-10-28 22:37 SWAN Dev\3rd Party\Fonts\DroidSansMono.ttf
..A..H. 344 2017-10-28 22:37 SWAN Dev\3rd Party\Fonts\DroidSansMono.ttf.me
..A..H. 193 2017-10-28 22:37 SWAN Dev\3rd Party\Fonts.me
..A..H. 193 2017-10-28 22:37 SWAN Dev\3rd Party.me
文件 3031 2018-02-09 17:16 SWAN Dev\Common\FilePathName.cs
..A..H. 264 2017-10-28 22:37 SWAN Dev\Common\FilePathName.cs.me
文件 3392 2017-10-28 22:37 SWAN Dev\Common\SDemoAnimation.cs
..A..H. 264 2017-10-28 22:37 SWAN Dev\Common\SDemoAnimation.cs.me
文件 1025 2017-10-28 22:37 SWAN Dev\Common\SelfAnimation.cs
..A..H. 264 2017-10-28 22:37 SWAN Dev\Common\SelfAnimation.cs.me
..A..H. 193 2017-10-28 22:37 SWAN Dev\Common.me
文件 240484 2017-10-28 22:37 SWAN Dev\ScreenshotHelper\Images\Photo\001.jpg
..A..H. 2294 2017-10-28 22:37 SWAN Dev\ScreenshotHelper\Images\Photo\001.jpg.me
文件 453943 2017-10-28 22:37 SWAN Dev\ScreenshotHelper\Images\Photo\002.jpg
..A..H. 2294 2017-10-28 22:37 SWAN Dev\ScreenshotHelper\Images\Photo\002.jpg.me
文件 159981 2017-10-28 22:37 SWAN Dev\ScreenshotHelper\Images\Photo\003.jpg
..A..H. 2294 2017-10-28 22:37 SWAN Dev\ScreenshotHelper\Images\Photo\003.jpg.me
文件 358097 2017-10-28 22:37 SWAN Dev\ScreenshotHelper\Images\Photo\004.jpg
..A..H. 2294 2017-10-28 22:37 SWAN Dev\ScreenshotHelper\Images\Photo\004.jpg.me
文件 540128 2017-10-28 22:37 SWAN Dev\ScreenshotHelper\Images\Photo\005.jpg
..A..H. 2294 2017-10-28 22:37 SWAN Dev\ScreenshotHelper\Images\Photo\005.jpg.me
..A..H. 193 2017-10-28 22:37 SWAN Dev\ScreenshotHelper\Images\Photo.me
..A..H. 193 2017-10-28 22:37 SWAN Dev\ScreenshotHelper\Images.me
文件 2454 2018-02-09 16:51 SWAN Dev\ScreenshotHelper\Materials\SpriteDefault.mat
..A..H. 181 2017-10-28 22:37 SWAN Dev\ScreenshotHelper\Materials\SpriteDefault.mat.me
文件 2454 2018-02-09 16:51 SWAN Dev\ScreenshotHelper\Materials\SpriteDiffuse.mat
..A..H. 181 2017-10-28 22:37 SWAN Dev\ScreenshotHelper\Materials\SpriteDiffuse.mat.me
..A..H. 193 2017-10-28 22:37 SWAN Dev\ScreenshotHelper\Materials.me
文件 25437 2017-10-28 22:37 SWAN Dev\ScreenshotHelper\Readme - Screenshot Helper 1.02.pdf
..A..H. 176 2017-10-28 22:37 SWAN Dev\ScreenshotHelper\Readme - Screenshot Helper 1.02.pdf.me
............此处省略26个文件信息
- 上一篇:mongoDb源码和笔记
- 下一篇:天津大学计算机网络SDN实验报告
评论
共有 条评论