Tag: compression

解压缩Windows 8 C上的ZIP文件#

我正在为Windows 8构建一个metro风格的应用程序,我有一个zip文件,我从Web服务下载,我想提取它。 我已经看到了压缩和解压缩的示例,但是需要对单个文件进行压缩/解压缩。 我有一个完整的目录结构,我需要提取。 这是我到目前为止: var appData = ApplicationData.Current; var file = await appData.LocalFolder.GetItemAsync(“thezip.zip”) as StorageFile; var decompressedFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(“tempFileName”, CreationCollisionOption.GenerateUniqueName); using (var decompressor = new Decompressor(await file.OpenSequentialReadAsync())) using (var decompressedOutput = await decompressedFile.OpenAsync(FileAccessMode.ReadWrite)) { var bytesDecompressed = await RandomAccessStream.CopyAsync(decompressor, decompressedOutput); } 但这并不好, bytesDecompressed变量总是零大小,但zip文件是1.2MB 这里的任何帮助将不胜感激。 编辑:回答,感谢Mahantesh 这是解压缩文件的代码: private async void UnZipFile() { var folder […]

在Python中压缩并使用解压缩C#解压缩的最简单方法(反之亦然)

我有一个程序,它有一个基于Mono的C#客户端和一个Python服务器,它通过TCP / IP套接字进行通信。 消息使用的主要是二进制格式,但每条消息的最大部分通常是嵌入的UTF-8字符串(英文)。 每条消息通常都很短(小于100字节),但有些消息可能更长(最多64K)。 交换了大量数据,我希望通过在传输数据时压缩数据来减少消息大小和带宽使用。 我最初的研究没有发现任何明显与2个标准库兼容的东西。 Python有一个zlib库,但我不能使用C#的DeflateStream或GZipStream(因为它们需要一个我没有的外部DLL),它似乎不适用于SharpZipLib的ZipOutputStream(给出“错误-3 – 不正确标题“回复”。 (那些不使用Mono的人可能会有更多运气 – 请参阅Duncan的答案。) 我有兴趣听到关于通过此通信链路实现压缩的简单方法,请记住,任何可能易于使用一种语言实现的解决方案都需要在另一种语言中具有等效性。 我接受一个专门针对UTF-8字符串而不是二进制消息的解决方案,尽管优先选择是压缩整个字节流。 理想情况下,我希望将外部依赖性保持在最低限度,但我意识到这可能不实用。 更新: 尝试使用SharpZipLib并在Python解码方面遇到重复错误,我真的可以使用已知可用的代码的具体建议,而不仅仅是针对一种语言或另一种语言的压缩库的建议。

C#更好的压缩远程桌面广播应用程序

我正在创建TCP远程桌面广播应用程序。 (服务器应用程序会像Team Viewer或VNC那样) 1. run on a PC listening for multiple clients on one Thread 2. and on another thread it will record the desktop every second 3. and it will broadcast the desktop for each connected client. 我需要使这个应用程序可以在12KBps上传和50KBps下载DSL连接(客户端和服务器)的连接上运行。 所以..我必须减少每秒发送的数据/图像的大小。 我尝试通过以下方式减少。 I. first i send a Bitmap frame of the desktop and each other time […]

.NET使用与加载时相同的质量保存jpeg

我有一个大炮数码相机,我设置它拍摄超细质量的照片,它输出一个3兆的.jpg文件。 如果我在ASP.NET中加载它(这有助于更改它的dpi分辨率或裁剪它或whaterver) imgPicture = Image.FromFile(Config.WorkDirectory + this.TempPhotoName); bmpPicture = new Bitmap(imgPicture); 然后我再次保存它: bmpModified.Save(Config.WorkDirectory + this.TempPhotoName,System.Drawing.Imaging.ImageFormat.Jpeg); 它输出的jpg大小只有700KB左右。 质量下降。 我也试过保存它: bmpPicture.Save(Config.WorkDirectory + this.TempPhotoName, codecJpeg, encparams); codecJpeg是哪里的 ImageCodecInfo codecJpeg = this.getEncoderInfo(“image/jpeg”); private ImageCodecInfo getEncoderInfo(string mimeType) { // Get image codecs for all image formats ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders(); // Find the correct image codec for (int i = […]

如何压缩文件

我想在C#中压缩文件和目录。 我在Internet上找到了一些解决方案,但它们非常复杂,我无法在我的项目中运行它们。 有人能建议我一个明确有效的解决方案吗?

为什么压缩小文件的gzip / deflate导致许多尾随零?

我正在使用以下代码在C#中压缩一个小的(~4kB)HTML文件。 byte[] fileBuffer = ReadFully(inFile, ResponsePacket.maxResponsePayloadLength); // Read the entire requested HTML file into a memory buffer inFile.Close(); // Close the requested HTML file byte[] payload; using (MemoryStream compMS = new MemoryStream()) // Create a new memory stream to hold the compressed HTML data { using (GZipStream gzip = new GZipStream(compMS, CompressionMode.Compress)) // Create a […]

使用RAR压缩文件

我有一个文本文件,我想要在获得指定的大小后压缩。 我已经看过GZipStream工作得很好,但RAR压缩要好得多。 我一直在寻找一个可以使用RAR 压缩文件的库(我真的不关心提取或解压缩),但我还找不到一个。

Zlib兼容的压缩流?

System.IO.Compression.GZipStream或System.IO.Compression.Deflate与zlib压缩兼容吗?

当我尝试压缩不同级别的pdf文件时,ITextSharp返回相同大小的pdf

我正在阅读pdf并使用itextsharp注入一些内容。 生成的byte[]与压缩级别一起传递给下面的方法。 public static byte[] method(byte[] pdf,int compressionlevel) { using (MemoryStream outputPdfStream1 = new MemoryStream()) { //PdfReader reader1 = new PdfReader(pdf); //PdfStamper stamper1 = new PdfStamper(reader1, outputPdfStream1); //int level = (int)compressionlevel; //if (level <= 9) // stamper1.Writer.CompressionLevel = (int)compressionlevel; //else // stamper1.Writer.SetFullCompression(); //stamper1.SetFullCompression(); //stamper1.Close(); //byte[] newfile = outputPdfStream1.ToArray(); //return newfile; PdfReader reader = new PdfReader(pdf); […]

GZipStream和解压缩

我有应该进行压缩的代码: FileStream fs = new FileStream(“g:\\gj.txt”, FileMode.Open); FileStream fd = new FileStream(“g:\\gj.zip”, FileMode.Create); GZipStream csStream = new GZipStream(fd, CompressionMode.Compress); byte[] compressedBuffer = new byte[500]; int offset = 0; int nRead; nRead = fs.Read(compressedBuffer, offset, compressedBuffer.Length); while (nRead > 0) { csStream.Write(compressedBuffer, offset, nRead); offset = offset + nRead; nRead = fs.Read(compressedBuffer, offset, compressedBuffer.Length); } fd.Close(); […]