zip to image

Oct 14, 2012 at 4:52 AM

I am trying to stream an image from a zip file to a picturebox by selecting it from a listbox loaded on form load event. I am probably way off here, but here's my code.

    Private Sub PicList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles PicList.SelectedIndexChanged
        Dim Pic As String
        Pic = PicList.SelectedItem.ToString
        Dim MyPic As ZipEntry
        Using zip As ZipFile = ZipFile.Read(Dir & "\Core.zip")
            If zip.EntryFileNames.Contains(Pic) Then
                For Each MyPic In zip
                    If MyPic.FileName = Pic Then
                        Using MyStream As New ZipOutputStream(ZipEntrySource.Stream)
                            Dim Gr As Image = Image.FromStream(MyStream)
                            PictureBox1.Image = Gr
                        End Using
                        Exit Sub
                    End If
                Next
            End If
        End Using
    End Sub

Oct 15, 2012 at 4:05 AM

 

System.NotSupportedException was unhandled  Message="Read"  Source="Ionic.Zip"  StackTrace:       at Ionic.Zip.ZipOutputStream.Read(Byte[] buffer, Int32 offset, Int32 count) in c:\DotNetZip\Zip\ZipOutputStream.cs:line 1583       at System.Drawing.Internal.GPStream..ctor(Stream stream)       at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)       at System.Drawing.Image.FromStream(Stream stream)       at Ie7Clone.Viewer.PicList_SelectedIndexChanged(Object sender, EventArgs e) in C:\Users\Emmery\Downloads\VB_NET_Web204585212007\Ie7Clone\Forms\Viewer.vb:line 20       at System.Windows.Forms.ListBox.OnSelectedIndexChanged(EventArgs e)       at System.Windows.Forms.ListBox.WmReflectCommand(Message& m)       at System.Windows.Forms.ListBox.WndProc(Message& m)       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)       at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)       at System.Windows.Forms.Control.SendMessage(Int32 msg, IntPtr wparam, IntPtr lparam)       at System.Windows.Forms.Control.ReflectMessageInternal(IntPtr hWnd, Message& m)       at System.Windows.Forms.Control.WmCommand(Message& m)       at System.Windows.Forms.Control.WndProc(Message& m)       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)       at System.Windows.Forms.ContainerControl.WndProc(Message& m)       at System.Windows.Forms.Form.WndProc(Message& m)       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)       at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)       at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)       at System.Windows.Forms.Control.DefWndProc(Message& m)       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)       at System.Windows.Forms.Control.WndProc(Message& m)       at System.Windows.Forms.ListBox.WndProc(Message& m)       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)       at System.Windows.Forms.Application.Run(ApplicationContext context)       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)       at Ie7Clone.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)       at System.Threading.ThreadHelper.ThreadStart()  InnerException: