Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

ZipStorer ZipFileEntry error on zfe.HeaderOffSet when adding a jpg file...

$
0
0

I am using this to create my new file:

jpg = System.IO.Path.Combine (documentsDirectory, "1");
 NSData imgData = imagemCam.AsJPEG();
 NSError err = null;
 if (imgData.Save(jpg+".jpg", false, out err))
 {
  Console.WriteLine("saved as " + jpg);
 } else {
  Console.WriteLine("NOT saved as" + jpg + " because" + err.LocalizedDescription);
 }

And i can add and compress all kind of files but when i try to compress the ones i create like this im getting an error on here ( zfe.FileOffset ) :

public void AddStream(Compression _method, string _filenameInZip, Stream _source, DateTime _modTime, string _comment)
    {
        if (Access == FileAccess.Read)
            throw new InvalidOperationException("Writing is not alowed");

        long offset;
        if (this.Files.Count==0)
            offset = 0;
        else
        {
            ZipFileEntry last = this.Files[this.Files.Count-1];
            offset = last.HeaderOffset + last.HeaderSize;
        }

        // Prepare the fileinfo
        ZipFileEntry zfe = new ZipFileEntry();
        zfe.Method = _method;
        zfe.EncodeUTF8 = this.EncodeUTF8;
        zfe.FilenameInZip = NormalizedFilename(_filenameInZip);
        zfe.Comment = (_comment == null ? "" : _comment);

        // Even though we write the header now, it will have to be rewritten, since we don't know compressed size or crc.
        zfe.Crc32 = 0;  // to be updated later
        //GETTING THE ERROR IN THE NEXT LINE
        zfe.HeaderOffset = (uint)this.ZipFileStream.Position;  // offset within file of the start of this local record

        zfe.ModifyTime = _modTime;

        // Write local header
        WriteLocalHeader(ref zfe);
        zfe.FileOffset = (uint)this.ZipFileStream.Position;

        // Write file to zip (store)
        Store(ref zfe, _source);
        _source.Close();

        this.UpdateCrcAndSizes(ref zfe);

        Files.Add(zfe);
    }

I really dont know why but im getting " object reference not set to an instance of an object " and i dont know what i can do maybe some information is missing in this files im creating... Any idea of what can i do? Someone knows other way for me to get a UIImageView.Image an save as jpg or png so maybe this piece of code works?


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>