Unity截屏&&压缩解压Zip
来源:互联网 发布:2017网络彩票代理加盟 编辑:程序博客网 时间:2024/04/29 07:18
StartCoroutine(GetCapture());
IEnumerator GetCapture()
{yield return new WaitForEndOfFrame();
int width = Screen.width;
int height = Screen.height;
Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);
tex.ReadPixels(new Rect(0, 0, width, height), 0, 0, true);
byte[] imagebytes = tex.EncodeToPNG();
// byte[] imagebytes = tex.EncodeToJPG(0~100);
// tex.Compress(false);
// tex.Apply();
System.DateTime t = System.DateTime.Now;
// strPath.Append(Application.persistentDataPath + "/" + "Pngs" + "/");
strPath.Append(Application.persistentDataPath + "/" + "Pngs" + "/");
System.IO.Directory.CreateDirectory(strPath.ToString());
strPath.AppendFormat("{0}_{1:D2}_{2:D2}_{3:D2}_{4:D2}_{5:D2}_{6}_Shot.png", t.Year, t.Month, t.Day, t.Hour, t.Minute, t.Second, t.Millisecond);
File.WriteAllBytes(strPath.ToString(), imagebytes);
//-- File.WriteAllBytes(Application.dataPath + "/screencapture.png", imagebytes);
Debug.Log("GetCapture:" + strPath.ToString());
}
//-----------------------------------------------------------------------------------------------------------------------------------
压缩zip
ICSharpCode.SharpZipLib.dll
http://icsharpcode.github.io/SharpZipLib/
using UnityEngine;
using System.Collections;
using ICSharpCode.SharpZipLib.Zip;
using System;
using System.IO;
public class ZipHelper
{
public static void GoCompress(string SourceFile, string TartgetFile)
{
string Source = SourceFile;
string Tartget = TartgetFile;
Directory.CreateDirectory(Path.GetDirectoryName(Tartget));
using (ZipOutputStream s = new ZipOutputStream(File.Create(Tartget)))
{
s.SetLevel(6);
Compress(Source, s);
s.Finish();
s.Close();
}
}
/// <summary>
/// 压缩文件夹
/// </summary>
/// <param name="source">源目录</param>
/// <param name="s">ZipOutputStream对象</param>
public static void Compress(string source, ZipOutputStream s)
{
string[] filenames = Directory.GetFileSystemEntries(source);
foreach (string file in filenames)
{
if (Directory.Exists(file))
{
// 递归压缩子文件夹
Compress(file, s);
}
else
{
using (FileStream fs = File.OpenRead(file))
{
byte[] buffer = new byte[4 * 1024];
// 此处去掉盘符,如D:\123\1.txt 去掉D:
ZipEntry entry = new ZipEntry(file.Replace(Path.GetPathRoot(file), ""));
// Debug.Log("===============:"+file.Replace(Path.GetPathRoot(file), ""));
entry.DateTime = DateTime.Now;
s.PutNextEntry(entry);
int sourceBytes;
do
{
sourceBytes = fs.Read(buffer, 0, buffer.Length);
s.Write(buffer, 0, sourceBytes);
} while (sourceBytes > 0);
}
}
}
}
/// <summary>
/// 解压缩
/// </summary>
/// <param name="sourceFile">压缩包完整路径地址</param>
/// <param name="targetPath">解压路径是哪里</param>
/// <returns></returns>
public static bool Decompress(string sourceFile, string targetPath)
{
if (!File.Exists(sourceFile))
{
throw new FileNotFoundException(string.Format("未能找到文件 '{0}' ", sourceFile));
}
if (!Directory.Exists(targetPath))
{
Directory.CreateDirectory(targetPath);
}
using (var s = new ZipInputStream(File.OpenRead(sourceFile)))
{
ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null)
{
if (theEntry.IsDirectory)
{
continue;
}
string directorName = Path.Combine(targetPath, Path.GetDirectoryName(theEntry.Name));
string fileName = Path.Combine(directorName, Path.GetFileName(theEntry.Name));
if (!Directory.Exists(directorName))
{
Directory.CreateDirectory(directorName);
}
if (!String.IsNullOrEmpty(fileName))
{
using (FileStream streamWriter = File.Create(fileName))
{
int size = 4096;
byte[] data = new byte[size];
while (size > 0)
{
streamWriter.Write(data, 0, size);
size = s.Read(data, 0, data.Length);
}
}
}
}
}
return true;
}
}
- Unity截屏&&压缩解压Zip
- unity-zip压缩与解压
- unity-zip压缩与解压
- unity ZIP压缩解压 Byte[]数据压缩解压
- ZIP压缩和解压
- linux zip 解压/压缩
- ZIP压缩和解压
- JAVA压缩/解压ZIP
- ZIP压缩与解压
- Java压缩/解压ZIP
- java zip压缩解压
- java,zip压缩,解压。
- 实现zip压缩解压
- centos zip 解压压缩
- zip压缩和解压
- ZIP 压缩解压命令
- 压缩解压ZIP
- Java Zip 压缩、解压
- 【PAT】A1058. A+B in Hogwarts (20)
- 第一个Maven实例
- 【PAT】A1061. Dating (20)
- Java的NIO之Scatter和Gather
- JSON.parse()和JSON.stringify()
- Unity截屏&&压缩解压Zip
- 【PAT】A1025. PAT Ranking (25)
- Ubuntu下安装JDK1.6
- MFC Win32 sendmessage丢失this指针,this指针变为NULL
- Codeforce 730J(贪心+01背包)
- 【PAT】A1056. Mice and Rice (25)
- Java的NIO之不同channel之间传输数据
- 汽车:圆梦不需5万元 大空间优质小型车推荐
- TinyXml API使用