Ejemplo n.º 1
0
 void ExtractImage(ArcFile arc, Entry entry, ImageFormat target_format)
 {
     using (var file = arc.OpenSeekableEntry(entry))
     {
         var src_format = ImageFormat.FindFormat(file, entry.Name);
         if (null == src_format)
         {
             throw new InvalidFormatException(string.Format("{1}: {0}", guiStrings.MsgUnableInterpretImage, entry.Name));
         }
         file.Position = 0;
         string target_ext = target_format.Extensions.FirstOrDefault() ?? "";
         string outname    = FindUniqueFileName(entry.Name, target_ext);
         if (src_format.Item1 == target_format)
         {
             // source format is the same as a target, copy file as is
             using (var output = ArchiveFormat.CreateFile(outname))
                 file.CopyTo(output);
             return;
         }
         ImageData image = src_format.Item1.Read(file, src_format.Item2);
         if (m_adjust_image_offset)
         {
             image = AdjustImageOffset(image);
         }
         using (var outfile = ArchiveFormat.CreateFile(outname))
         {
             target_format.Write(outfile, image);
         }
     }
 }