Results 1 to 2 of 2

Thread: Open & Display image in win form

  1. #1

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539

    Open & Display image in win form

    Hey all firstly ive kinda got two things i wana do here

    1, open file dialog, select image and display it in a picture box
    2, have some access to the file for uploading to a server
    (2 in more detail, ive created a object in my website application for image uploading and resizing, my CMS is in fact a windows application and ive referenced the dll for the .net website in my application, so i use use most of the code in the site. i need to be able to open/show a pic and then save it along with other data to my site. saving the data works just need to sort out the image bit.

    First question, how do i display the image in a picture box
    Current Code
    VB Code:
    1. Private Function OpenFile() As FileStream
    2.  
    3.         ' Displays an OpenFileDialog and shows the read/only files.
    4.  
    5.         Dim DlgOpenFile As New System.Windows.Forms.OpenFileDialog
    6.         DlgOpenFile.ShowReadOnly = True
    7.         Dim Fs As FileStream
    8.  
    9.         If DlgOpenFile.ShowDialog() = DialogResult.OK Then
    10.  
    11.             ' If ReadOnlyChecked is true, uses the OpenFile method to
    12.             ' open the file with read/only access.
    13.  
    14.             If DlgOpenFile.ReadOnlyChecked = True Then
    15.  
    16.                 Return DlgOpenFile.OpenFile()
    17.  
    18.                 ' Otherwise, opens the file with read/write access.
    19.  
    20.             Else
    21. 'this below is wrong because its crashing out
    22.                 Dim Path As String = DlgOpenFile.FileName
    23.                 Dim imageStream = New FileStream(Path, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite)
    24.  
    25.                 Me.PictureBox1.Image.FromStream(imageStream)
    26.                 Me.PictureBox1.Update()
    27.  
    28.             End If
    29.  
    30.         End If

    Second question.
    I guess i can just pass the stream to to asp.net because that using fileField to upload the file, is this correct ?
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Open & Display image in win form

    well just for loading the image:
    remember that MOST functions in .NET DO NOT modify the value that you pass into them, but they RETURN the modified value. So when calling Image.FromStream, it is returning the opened image and not modifying the picturebox. So you would have to do this:

    Me.PictureBox1.Image = Image.FromStream(imageStream)

    You can simply load it this way also, if you don't want to use streams:
    Image.FromFile(fileName)
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width