Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    AceKill3r's Avatar
    Join Date
    Feb 2011
    Gender
    male
    Posts
    181
    Reputation
    22
    Thanks
    39
    My Mood
    Aggressive

    [Help]PictureBox and Image properties[solved]

    Hey, i was wondering how to get an Image Size from the picturebox..

    Im making an Image converter and have the PictureBox1.Image = OpenFileDialog yadda yadda yadda.

    But how would i show the image size ? ( once the user selects the image, a label will show the image size)

    Cheers for the answer's :-)

  2. #2
    Lyoto Machida's Avatar
    Join Date
    Jan 2011
    Gender
    male
    Location
    Far away with girls
    Posts
    3,734
    Reputation
    133
    Thanks
    1,621
    My Mood
    Aggressive
    I think its this:

    Code:
    HeightLabel.Text = PictureBox1.Image.Height ' Get the height
    WidthLabel.Text = PictureBox1.Image.Width ' Get the width
    Hope it works.

  3. #3
    AceKill3r's Avatar
    Join Date
    Feb 2011
    Gender
    male
    Posts
    181
    Reputation
    22
    Thanks
    39
    My Mood
    Aggressive
    Quote Originally Posted by -WØW'' View Post
    I think its this:

    Code:
    HeightLabel.Text = PictureBox1.Image.Height ' Get the height
    WidthLabel.Text = PictureBox1.Image.Width ' Get the width
    Hope it works.
    Yes that works. However

    I have to choose an image first, then choose another image, then go back to the first one i chose before the label's display the heigh/width..

    any idea how to fix?

  4. #4
    Lyoto Machida's Avatar
    Join Date
    Jan 2011
    Gender
    male
    Location
    Far away with girls
    Posts
    3,734
    Reputation
    133
    Thanks
    1,621
    My Mood
    Aggressive
    Quote Originally Posted by AceKill3r View Post
    Yes that works. However

    I have to choose an image first, then choose another image, then go back to the first one i chose before the label's display the heigh/width..

    any idea how to fix?
    I didn understand but i think you need to put like this:
    Code:
    PictureBox1.Image = OpenFileDialog.Filename
    HeightLabel.Text = PictureBox1.Image.Height ' Get the height
    WidthLabel.Text = PictureBox1.Image.Width ' Get the width
    In a button or something..
    I think is that..

  5. #5
    ♪~ ᕕ(ᐛ)ᕗ's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Uterus
    Posts
    9,119
    Reputation
    1096
    Thanks
    1,970
    My Mood
    Doh
    Quote Originally Posted by -WØW'' View Post


    I didn understand but i think you need to put like this:
    Code:
    PictureBox1.Image = OpenFileDialog.Filename
    HeightLabel.Text = PictureBox1.Image.Height ' Get the height
    WidthLabel.Text = PictureBox1.Image.Width ' Get the width
    In a button or something..
    I think is that..
    Code:
    PictureBox1.Image = Image.FromFile(OpenFileDialog1.Filename)
    xD

  6. #6
    Lyoto Machida's Avatar
    Join Date
    Jan 2011
    Gender
    male
    Location
    Far away with girls
    Posts
    3,734
    Reputation
    133
    Thanks
    1,621
    My Mood
    Aggressive
    Quote Originally Posted by 3Li0 View Post
    Code:
    PictureBox1.Image = Image.FromFile(OpenFileDialog1.Filename)
    xD
    yeah that, i just copy and paste his code xD
    Last edited by Lyoto Machida; 02-12-2011 at 11:42 AM.

  7. #7
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Bare with me here, you're saying you want to select an image, then select another image, then go back to the first one and display it's width height?

    Perhaps create a list of images, add to it, make the picturebox display the first image and set the label text in the very next step.

    I'm still not 100% sure what your final purpose is though, why the need to open 2 images? A picturebox can only display 1 and can't hold any in memory...

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  8. #8
    ♪~ ᕕ(ᐛ)ᕗ's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Uterus
    Posts
    9,119
    Reputation
    1096
    Thanks
    1,970
    My Mood
    Doh
    Quote Originally Posted by Jason View Post
    Bare with me here, you're saying you want to select an image, then select another image, then go back to the first one and display it's width height?

    Perhaps create a list of images, add to it, make the picturebox display the first image and set the label text in the very next step.

    I'm still not 100% sure what your final purpose is though, why the need to open 2 images? A picturebox can only display 1 and can't hold any in memory...
    yea, maybe he means a listbox with images, and when you select an image it will show the image and the size.....

    Try this:
    Code:
        Public WithEvents timer1 As New Timer
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim x As New OpenFileDialog With {.Title = "Select image.."}
            x.ShowDialog()
            ListBox1.Items.Add(x.FileName)
            timer1.Start()
        End Sub
    
        Private Sub Timer1_Tick() Handles timer1.Tick
            Try
                PictureBox1.Image = Image.FromFile(ListBox1.SelectedItem.ToString)
                Label1.Text = PictureBox1.Image.Height
                Label2.Text = PictureBox1.Image.Width
            Catch ex As Exception
    
            End Try
        End Sub

  9. #9
    Blubb1337's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Germany
    Posts
    5,915
    Reputation
    161
    Thanks
    3,108
    [highlight="vb"]' Load the Image
    Dim objImage As System.Drawing.Image = _
    System.Drawing.Image.FromFile("C:\MyImage.gif")

    ' Get Height and Width
    Dim Width as integer = objImage.Width
    Dim Height as integer = objImage.Height
    [/highlight]

    Bla, nvm <_<.



  10. #10
    AceKill3r's Avatar
    Join Date
    Feb 2011
    Gender
    male
    Posts
    181
    Reputation
    22
    Thanks
    39
    My Mood
    Aggressive
    Quote Originally Posted by Jason View Post
    Bare with me here, you're saying you want to select an image, then select another image, then go back to the first one and display it's width height?

    Perhaps create a list of images, add to it, make the picturebox display the first image and set the label text in the very next step.

    I'm still not 100% sure what your final purpose is though, why the need to open 2 images? A picturebox can only display 1 and can't hold any in memory...
    No,No,No - Thats what happenes.. i have to select 2 different image's for the labels to show the width & height.. ill put up a preview gimme 2 minutes

  11. #11
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by AceKill3r View Post
    No,No,No - Thats what happenes.. i have to select 2 different image's for the labels to show the width & height.. ill put up a preview gimme 2 minutes
    So, you want to display the width and height of 2 different images?

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  12. #12
    AceKill3r's Avatar
    Join Date
    Feb 2011
    Gender
    male
    Posts
    181
    Reputation
    22
    Thanks
    39
    My Mood
    Aggressive


    The video will sort of explain whats going on!

  13. #13
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by AceKill3r View Post


    The video will sort of explain whats going on!
    Hmm, what code are you using at this stage on the Button's "click" event, I should be able to figure it out from there. I think I know what the problem COULD be, I'll have to see the code before I'm sure though.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  14. #14
    AceKill3r's Avatar
    Join Date
    Feb 2011
    Gender
    male
    Posts
    181
    Reputation
    22
    Thanks
    39
    My Mood
    Aggressive
    Here is all my code i've got so far.. the code is under ' TextBox1_TextChanged ' event..

    [highlight=vb.net]

    Public Class Form1
    Dim OpenFileDialog1 As New OpenFileDialog
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    With OpenFileDialog1
    .CheckFileExists = True
    .ShowReadOnly = False
    .Filter = "ICO(*.ico)|*.ico|JPG(*.jpg)|*.jpg*|BMP(*.bmp)|*.b mp|TIFF(*.tiff)|*.tiff|GIF(*.gif)|*.gif|PNG(*.png) |*.png"
    If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
    TextBox1.Text = OpenFileDialog1.FileName
    PictureBox3.Image = Image.FromFile(OpenFileDialog1.FileName)
    End If
    End With
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    TextBox1.Text = ""
    If TextBox1.Text = "" Then
    Dim OpenFileDialog1 As New OpenFileDialog
    With OpenFileDialog1
    .CheckFileExists = True
    .ShowReadOnly = False
    .Filter = "ICO(*.ico)|*.ico|JPG(*.jpg)|*.jpg*|BMP(*.bmp)|*.b mp|TIFF(*.tiff)|*.tiff|GIF(*.gif)|*.gif|PNG(*.png) |*.png"
    .FilterIndex = 1
    If .ShowDialog = DialogResult.OK Then
    TextBox1.Text = OpenFileDialog1.FileName
    ' Load the specified file into a PictureBox control.
    PictureBox3.Image = Image.FromFile(.FileName)
    End If
    End With
    End If
    End Sub
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
    Button2.Enabled = True
    Try
    HeightLabel.Text = PictureBox3.Image.Height ' Get the height
    WidthLabel.Text = PictureBox3.Image.Width ' Get the width
    Catch ax As Exception
    End Try
    End Sub
    Private Sub OpenImageToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenImageToolStripMenuItem.Click
    If TextBox1.Text = "" Then
    MsgBox("Please select your image before clicking this!", MsgBoxStyle.Critical, "")
    Else
    Process.Start(TextBox1.Text)
    End If
    End Sub
    Private Sub CloseMenuToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseMenuToolStripMenuItem.Click
    ContextMenuStrip1.Hide()
    End Sub
    End Class
    ' ooo.Filter = "ICO(*.ico)|*.ico|JPG(*.jpg)|*.jpg*|BMP(*.bmp)|*.b mp|TIFF(*.tiff)|*.tiff|GIF(*.gif)|*.gif|PNG(*.png) |*.png"
    [/highlight]
    Last edited by Jason; 02-12-2011 at 11:34 PM. Reason: Nicer tags :3

  15. #15
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Okay, firstly remove the TextChanged event and all it's code completely, we'll handle it differently

    Now remove your definition of "OpenFileDialog1" completely as well, we'll recode the Button2_Click sub to this:

    [highlight=vb.net]
    Using ofd As New OpenFileDialog With {.CheckFileExists = True, .ShowReadOnly = False, .Filter = "ICO(*.ico)|*.ico|JPG(*.jpg)|*.jpg*|BMP(*.bmp)|*.b mp|TIFF(*.tiff)|*.tiff|GIF(*.gif)|*.gif|PNG(*.png) |*.png"}
    If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
    Dim nextImg As Image = Image.FromFile(ofd.FileName)
    HeightLabel.Text = nextImg.Height.ToString
    WidthLabel.Text = nextImg.Width.ToString
    PictureBox1.Image = nextImg
    End If
    End Using
    [/highlight]

    Now when you press okay in the OFD, it will set the pictureboxes image correctly, and display the image's height and width straight away. It's always best to call relevant code in the same event that you start from, rather than from another event which might not sync correctly.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

Page 1 of 2 12 LastLast