How to pick up the Width and Height from images in a Folder

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gcarterm
    New Member
    • Jan 2010
    • 2

    How to pick up the Width and Height from images in a Folder

    Hello -- first timer. I'm working with Excel Visual Basic. I need to get the width and height pixel dimensions for images in a folder. This seems like a Holy Grail proposition. I've looked everywhere.

    Know that I'm not a professional programmer, just hobbyist. I know the code can't be that complex. I just don't know the syntax.

    Thanks for any help you can give.

    Mike
  • smartchap
    New Member
    • Dec 2007
    • 236

    #2
    Welcome newbie gcarterm
    For this problem put DirListBox, DriveListBox, FileListBox, Label & a picture box in a form. Use following code (& other code for ListBoxes) to display the size of an image:

    [code]
    Private Sub File1_Click()
    Me.Picture1.Pic ture = LoadPicture(Me. Dir1.Path & "\" & Me.File1.FileNa me)
    'display size of the image:
    Me.Label1.Capti on = Int(Me.Picture1 .Picture.Width / 26.458) & "x" & Int(Me.Picture1 .Picture.Height / 26.458)
    End Sub
    [\code]

    Comment

    • vb5prgrmr
      Recognized Expert Contributor
      • Oct 2009
      • 305

      #3
      Smartchap, that would be a forward slash (/) for the code block and gcarterm, to get rid of the calculations in smartchap's code, set the picture boxes scalemode to vbpixels or if you do not want to display the picture, use a stdPicture Object...
      Code:
      Dim P As StdPicture
      Set P = LoadPicture("pathfilename")
      MsgBox P.Width & " x " & P.Height
      Edit:and if the images are bitmaps *.bmp then see some of the results of this search http://search.yahoo.com/search?fr=yf...tmapinfoheader

      Good Luck

      Comment

      • gcarterm
        New Member
        • Jan 2010
        • 2

        #4
        Thanks to Smartchap and vb5prgrmr for the quick replies. Working on the advice.

        Smarthchap, I'm not using a form, just Excel VB code in a module. I just need to pick up the image dimensions.

        vb5prgrmr, I used the code:
        # Set P = LoadPicture("pa thfilename")
        # MsgBox P.Width & " x " & P.Height
        and this gave me figures, but the W and H were really high.

        When I divided Smartchap's figure, 26.458, into the W and H, I came up with the correct dimension. I think it has to do with Scalemode. The VBA Reference I found on line explained this but didn't give an example of the Scalemode syntax (
        expression.Scal eMode with numeric settings
        .

        In simple terms (for my Newbie mind), could one of you modify the code to yield the W and H dimensions in actual pic.jpg terms; that is so that

        # Set P = LoadPicture("pa thfilename")
        # MsgBox P.Width & " x " & P.Height

        results in 80 and 109 rather than 2117 and 2884 or am I simply stuck with dividing the results by 26.458? In other words, how does the Scalemode syntax work?

        Mike

        Comment

        • vb5prgrmr
          Recognized Expert Contributor
          • Oct 2009
          • 305

          #5
          Well you can try to set me.scalemode = vbpixels or if it does not work, you will have to use smartchap's division...



          Good Luck

          Comment

          • smartchap
            New Member
            • Dec 2007
            • 236

            #6
            Dear vb5prgrmr

            Thanks for telling about slash, actually that day I was a little hurry & just pressed slash without even noticing the result otherwise would have edited that.
            Actually on 4th Feb'10 I had undergone two major surgeries & was not able to check any mail, even today I can't sit for a long before computer, so bear with me. Soon I will give the code for dimensions as required by gcarterm. Actually in my code division by 26.458 depends on type of image (black or colour) also on No. of Megapixels in the image. If photo / image is taken from a digital camera setting some other MP or scanned with different pixel depth, this figure may change. So I will workout & post a code in which you can choose No. of Pixels & dimensions of the image will be displayed.

            Comment

            Working...