本文整理汇总了C#中CompressionType类的典型用法代码示例。如果您正苦于以下问题:C# CompressionType类的具体用法?C# CompressionType怎么用?C# CompressionType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CompressionType类属于命名空间,在下文中一共展示了CompressionType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompressBytes
public static byte[] CompressBytes(CompressionType type, byte[] fileBytes)
{
MemoryStream ms = new MemoryStream();
Stream compressedStream = null;
if (type == CompressionType.deflate)
{
compressedStream = new DeflateStream(ms, CompressionMode.Compress, true);
}
else if (type == CompressionType.gzip)
{
compressedStream = new GZipStream(ms, CompressionMode.Compress, true);
}
if (type != CompressionType.none)
{
//write the bytes to the compressed stream
compressedStream.Write(fileBytes, 0, fileBytes.Length);
compressedStream.Close();
byte[] output = ms.ToArray();
ms.Close();
return output;
}
//not compressed
return fileBytes;
}
示例2: SetMaxSize
private static void SetMaxSize(CompressionType compression, ImporterSettings settings)
{
switch (compression)
{
case CompressionType.Dxt:
case CompressionType.Dxt1:
case CompressionType.Dxt5:
case CompressionType.ShelfHeroshot:
case CompressionType.ShelfHeroshotBlackWhite:
settings.MaxSize = 1024;
break;
case CompressionType.Dxt_2K:
case CompressionType.Dxt1_2K:
case CompressionType.Dxt5_2K:
case CompressionType.NoesisLifestyleFeatures:
case CompressionType.FilterTest:
settings.MaxSize = 1024*2;
break;
case CompressionType.Thumbnail140:
case CompressionType.Thumbnail256:
settings.MaxSize = 256;
break;
default:
settings.MaxSize = 1024*2;
break;
}
}
示例3: RequestImage
public void RequestImage(ImageType img_type, CompressionType comp_type = CompressionType.LZ4)
{
byte[] send_params = new byte[2];
switch (comp_type)
{
case CompressionType.Uncompressed:
send_params[0] = COMPR_TYPE_NONE;
break;
case CompressionType.LZ4:
send_params[0] = COMPR_TYPE_LZ4;
break;
default:
break;
}
switch (img_type)
{
case ImageType.Depth:
send_params[1] = IMG_TYPE_DEPTH;
break;
case ImageType.Image:
send_params[1] = IMG_TYPE_IMAGE;
break;
case ImageType.IR:
send_params[1] = IMG_TYPE_IR;
break;
default:
break;
}
sock.Send(send_params);
buf = sock.Recv();
switch (comp_type)
{
case CompressionType.Uncompressed:
buf.CopyTo(decompressed, 0);
break;
case CompressionType.LZ4:
dcmp.DecompressKnownSize(buf, decompressed, 640 * 480 * (img_type == ImageType.Depth ? depth_bpp : (img_type == ImageType.Image ? image_bpp : ir_bpp)));
break;
default:
break;
}
bmp_d = bmp.LockBits(new Rectangle(0, 0, 640, 480), ImageLockMode.WriteOnly,
(img_type == ImageType.Depth ? PixelFormat.Format16bppRgb555 : (img_type == ImageType.Image ? PixelFormat.Format24bppRgb : PixelFormat.Format8bppIndexed)));
// http://msdn.microsoft.com/en-us/library/system.drawing.imaging.bitmapdata.aspx
IntPtr ptr = bmp_d.Scan0;
// Copy the RGB values back to the bitmap
System.Runtime.InteropServices.Marshal.Copy(decompressed, 0, ptr, bmp_d.Width * bmp_d.Height * (img_type == ImageType.Depth ? depth_bpp : (img_type == ImageType.Image ? image_bpp : ir_bpp))); // elvileg mindenképp 640x480x2, fixme
// Unlock the bits.
bmp.UnlockBits(bmp_d);
// elvileg ez a leggyorsabb mód a másolásra, ennél gyorsabban nem lehet...
}
示例4: ZipEntry
internal ZipEntry(Stream fileStream, string entryName, CompressionType compressionType)
: this(entryName, compressionType)
{
if (!fileStream.CanRead) throw new IOException("Can not read from file stream");
_fileStream = fileStream;
IsDirty = true;
}
示例5: UglyStream
/// <summary>
/// Constructor
/// </summary>
/// <param name="StreamUsing">The stream for the page</param>
/// <param name="Compression">The compression we're using (gzip or deflate)</param>
/// <param name="Type">Minification type to use (defaults to HTML)</param>
public UglyStream(Stream StreamUsing, CompressionType Compression, MinificationType Type = MinificationType.HTML)
: base()
{
this.Compression = Compression;
this.StreamUsing = StreamUsing;
this.Type = Type;
}
示例6: NetworkUpdateWorld
void NetworkUpdateWorld(byte[] data)
{
World world = (World)FindObjectOfType(typeof(World));
world.loadDefaultWorld();
string size = "";
CompressionType compression;
using (MemoryStream stream = new MemoryStream(data))
{
using (WorldInputStream reader = new WorldInputStream(stream))
{
reader.Read(world);
size = stream.Length.GetSizeReadable();
compression = reader.compressionType;
}
}
UnityEngine.Debug.Log("world received (" + size + " | " + compression + ")");
GameObject player = GameObject.FindWithTag("Player");
if (player)
player.SendMessage("Respawn");
CircularObjectPool.instance.RecallAllObjectsForType("Debris");
}
示例7: Test_Compress
// File : Create new, Append to existing, Raz existing
// ArchiveType : Rar = 0, Zip = 1, Tar = 2, SevenZip = 3, GZip = 4
// CompressionType : None = 0, GZip = 1, BZip2 = 2, PPMd = 3, Deflate = 4, Rar = 5, LZMA = 6, BCJ = 7, BCJ2 = 8, Unknown = 9,
// Zip compression type : BZip2
// GZip compression type : GZip
// example from https://github.com/adamhathcock/sharpcompress/wiki/API-Examples
// this example dont work to add file to an existing zip
public static void Test_Compress(string compressFile, IEnumerable<string> files, string baseDirectory = null, ArchiveType archiveType = ArchiveType.Zip,
CompressionType compressionType = CompressionType.BZip2, CompressionLevel compressionLevel = CompressionLevel.Default)
{
//FileOption
if (baseDirectory != null && !baseDirectory.EndsWith("\\"))
baseDirectory = baseDirectory + "\\";
CompressionInfo compressionInfo = new CompressionInfo();
compressionInfo.DeflateCompressionLevel = compressionLevel;
compressionInfo.Type = compressionType;
//Trace.WriteLine("SharpCompressManager : DeflateCompressionLevel {0}", compressionInfo.DeflateCompressionLevel);
//Trace.WriteLine("SharpCompressManager : CompressionType {0}", compressionInfo.Type);
Trace.WriteLine($"open compressed file \"{compressFile}\"");
// File.OpenWrite ==> OpenOrCreate
using (FileStream stream = File.OpenWrite(compressFile))
using (IWriter writer = WriterFactory.Open(stream, archiveType, compressionInfo))
//using (IWriter writer = WriterFactory.Open(stream, archiveType, CompressionType.BZip2))
{
foreach (string file in files)
{
string entryPath;
if (baseDirectory != null && file.StartsWith(baseDirectory))
entryPath = file.Substring(baseDirectory.Length);
else
entryPath = zPath.GetFileName(file);
Trace.WriteLine($"add file \"{entryPath}\" \"{file}\"");
writer.Write(entryPath, file);
}
}
}
示例8: ArchiveStreamReadExtractAll
protected void ArchiveStreamReadExtractAll(IEnumerable<string> testArchives, CompressionType compression)
{
foreach (var path in testArchives)
{
ResetScratch();
using (Stream stream = File.OpenRead(path))
using (var archive = ArchiveFactory.Open(stream))
{
Assert.IsTrue(archive.IsSolid);
using (var reader = archive.ExtractAllEntries())
{
ReaderTests.UseReader(this, reader, compression);
}
VerifyFiles();
if (archive.Entries.First().CompressionType == CompressionType.Rar)
{
return;
}
foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
{
entry.WriteToDirectory(SCRATCH_FILES_PATH,
ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite);
}
}
VerifyFiles();
}
}
示例9: ImaqFlatten
public static RawData ImaqFlatten(Image image, FlattenType type, CompressionType compression, int quality)
{
uint size = 0;
IntPtr rv = Interop.imaqFlatten(image.NativeObj, type, compression, quality, ref size);
return new RawData(rv, size, true);
}
示例10: UnCompress
private static byte[] UnCompress(this byte[] bytes, CompressionType type)
{
if (bytes == null || bytes.Length == 0)
return new byte[0];
using (var stream = type == CompressionType.GZip
? (Stream)new GZipStream(new MemoryStream(bytes), CompressionMode.Decompress)
: new DeflateStream(new MemoryStream(bytes), CompressionMode.Decompress))
{
var buffer = new byte[4096];
using (var memory = new MemoryStream())
{
int count;
do
{
count = stream.Read(buffer, 0, buffer.Length);
if (count > 0)
{
memory.Write(buffer, 0, count);
}
}
while (count > 0);
bytes = memory.ToArray();
}
}
return bytes;
}
示例11: Open
public static IWriter Open(Stream stream, ArchiveType archiveType, CompressionType compressionType, bool leaveOpen = false)
{
return Open(stream, archiveType, new CompressionInfo
{
Type = compressionType
}, leaveOpen);
}
示例12: Open
public static IWriter Open(Stream stream, ArchiveType archiveType, CompressionType compressionType)
{
return Open(stream, archiveType, new CompressionInfo
{
Type = compressionType
});
}
示例13: CompressAsync
public static async Task<Stream> CompressAsync(CompressionType type, Stream original)
{
using (var ms = new MemoryStream())
{
Stream compressedStream = null;
if (type == CompressionType.deflate)
{
compressedStream = new DeflateStream(ms, CompressionMode.Compress);
}
else if (type == CompressionType.gzip)
{
compressedStream = new GZipStream(ms, CompressionMode.Compress);
}
if (type != CompressionType.none)
{
using (compressedStream)
{
await original.CopyToAsync(compressedStream);
}
//NOTE: If we just try to return the ms instance, it will simply not work
// a new stream needs to be returned that contains the compressed bytes.
// I've tried every combo and this appears to be the only thing that works.
byte[] output = ms.ToArray();
return new MemoryStream(ms.ToArray());
}
//not compressed
return original;
}
}
示例14: Close
public void Close()
{
if (Map != null) { Map.Dispose(); Map = null; }
Address = null;
Length = 0;
Compression = CompressionType.None;
}
示例15: Decompress
public static byte[] Decompress(string file, CompressionType cmp)
{
byte[] ret = new byte[0];
switch (cmp)
{
case CompressionType.Uncompressed:
ret = File.ReadAllBytes(file);
break;
case CompressionType.Kosinski:
ret = Kosinski.Decompress(file);
break;
case CompressionType.KosinskiM:
ret = ModuledKosinski.Decompress(file, LevelData.littleendian ? Endianness.LittleEndian : Endianness.BigEndian);
break;
case CompressionType.Nemesis:
ret = Nemesis.Decompress(file);
break;
case CompressionType.Enigma:
ret = Enigma.Decompress(file, LevelData.littleendian ? Endianness.LittleEndian : Endianness.BigEndian);
break;
case CompressionType.SZDD:
ret = SZDDComp.SZDDComp.Decompress(file);
break;
default:
break;
}
return ret;
}