Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET PictureBox from memory?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #19358 |

    I used the example to extract a zip into memory (RAM_Drive:\folder\) and am now trying to display an image from the ramdrive into a picturebox. The problem is that when I use:

    pbMain.Image = Image.FromFile(thefile);

    I get:

    An unhandled exception of type ‘System.NotSupportedException’ occurred in mscorlib.dll

    Additional information: The given path’s format is not supported.

    I figure that the problem is I have to make a memory stream and then use Image.FromStream. How would I write a file fromt he xceed filesystem to a memeory stream? Any help would be apprecieated. Thanks.

    Imported from legacy forums. Posted by Hektik (had 3342 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi!

    Don’t worry, the answer is much simpler. First, if you stick with unzipping the file in a MemoryFile first, you do this:

    <code>using( Stream theStream = theFile.OpenRead() )
    {
    pbMain.Image = Image.FromStream( theStream );
    }</code>

    Every AbstractFile has an OpenRead method. A MemoryFile is an AbstractFile. A DiskFile is an AbstractFile. But wait! A ZippedFile is an AbstractFile!!! So why not do this:

    <code>// Let’s say “zip” is your ZipArchive instance.
    // Get a reference on the file INSIDE the ZipArchive directly!!!
    AbstractFile imageFile = zip.GetFile( “YourImageFilenameInTheZip.bmp” );

    if( imageFile.Exists )
    {
    using( Stream theStream = theFile.OpenRead() )
    {
    pbMain.Image = Image.FromStream( theStream );
    }
    }</code>

    As you can see, you don’t even need to copy that file to a MemoryFile first. Just grab a stream on it!

    Imported from legacy forums. Posted by Martin (had 175 views)

    User (Old forums)
    Member
    Post count: 23064

    Ah, thanks for the speedy reply 😀 However…the name of the image file isn’t something that I actually know (I’m trying to make a comic/manga viewer) the image name could be anything. Is there any way to use the second method to somehow put all the images into an array so i can manually go through each image file? I currently have an array like this:

    foreach ( AbstractFile f in folder.GetFiles(true, new NameFilter(“*.jpg|*.jpeg|*.bmp|*.gif|*.png”)))
    {
    zipFiles[x] = f.FullName;
    }

    Could I possibly use a loop like

    AbstractFile imageFile = zip.GetFile( zipFiles[x] );

    Of course, I’d have to change f.FullName to f.Name, but other than that, I think I could make an array of imageFiles to queue up for reading/viewing.

    I’m sorry if im asking too much from you, but as a beginner in c#, I need a kick in the right direction 😀 Thanks for the help.

    Imported from legacy forums. Posted by Hektik (had 220 views)

    User (Old forums)
    Member
    Post count: 23064

    Sure! But I’d do it like this:

    <code>// Let’s say “zip” is your ZipArchive:
    AbstractFile[] imageFiles = zip.GetFiles( true, “*.jpg|*.jpeg|*.bmp|*.gif|*.png” );

    // Here you can create “imageFiles.Length” picture boxes.
    // Let’s say they are named pbPics[].
    int index = 0;

    foreach( AbstractFile imageFile in imageFiles )
    {
    using( Stream imageStream = imageFile.OpenRead() )
    {
    pbPics[ index++ ].Image = Image.FromStream( imageStream );
    }
    }</code>

    Imported from legacy forums. Posted by Martin (had 4244 views)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.