Solved

width and height for  HTML <IMG> tag from VB

Posted on 1997-06-17
8
324 Views
Last Modified: 2008-03-06
Does anybody know how I can determine the width/height
of a gif picture in the measurements that a Html browser
expects to see in
<IMG height="50" width="120" SRC=".......>
Please give me some code!!!
0
Comment
Question by:VB-tinkerer
  • 4
  • 4
8 Comments
 
LVL 7

Expert Comment

by:tward
ID: 1427398
If you have read the line in then simply use:

Position = Instr(1,TheLine,"height",0)
SpacePosition = Instr(Position, TheLine, " ", 0)

Height = Mid(TheLine, Position+8, SpacePosition-(Position+8))

This should get the height then do the same thing with some different numbers to get the width.
0
 

Author Comment

by:VB-tinkerer
ID: 1427399
I obviously didn't express myself very well.  What I want to do is
load a picture in VB and then determine the width number and the height number of the picture, so that I can use it in my html statement:

      <IMG height="50" width="120" SRC=".......>

In other words I want to be able to determine what the numbers should be so that I can write the above statement
0
 
LVL 7

Expert Comment

by:tward
ID: 1427400
Oh, can't you just load it into a picture box that has the autosize set to true, what happens is the picture box will shrink or expand to fit the image loaded into it, then just take the width and height from the size of the picturebox..?  I know VB 5.0's pictureboxes supports GIF and JPEG but you didn't state which version of VB you were using.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:VB-tinkerer
ID: 1427401
I am quite familiar with the .width and .height properties of the picture box.  However none of the measurements available seem to correspond to the measurements required in the HTML pages.  I tried to find a conversion factor - but the conversion factor seems to be non-constant:

e.g.  Picture Term_Small.gif

                       VB                                   HTML
height            990                                   62
width            1470                                   94

Home.gif
height             705                                    47
width               420                                   24

As the original question states:  I want some code that gives me
the MEASUREMENTS THAT A HTML BROWSER EXPECTS TO SEE
0
 
LVL 7

Expert Comment

by:tward
ID: 1427402
Since the Picturebox give the values in twips by default take the
width/screen.twipsperpixelX
height/screen.twipsperpixelY

or set your form to be in Pixels ScaleMode.

The Height and Width of Images in HTML is needed in Pixels.
0
 

Author Comment

by:VB-tinkerer
ID: 1427403
Thanks - this seems to work fine.
If you know a faster way to do this (e.g. reading the .GIF file directly and getting the information from there) that would be great!!

Do you know how I now can award you the points?  I don't seem to have a rating possibility anymore?

Thanks again.
0
 
LVL 7

Accepted Solution

by:
tward earned 150 total points
ID: 1427404
You couldn't give the points because I only put that in as a comment.  I do have a book here that tells what the header is:

DB   GIF87a
DW  SCREEN_WIDTH
DW  SCREEN_DEPTH
DB  GLOBAL_FLAG_BYTE
DB  BACKGROUND_COLOR
DB  0

       COLOR MAP - GLOBAL_FLAG_BYTE tells you how many
                                there will be (First 3 bits of the Byte) you                                        need to add 1 to it and shift left 3 times.
                                Maximum value is  is 8 and one shifted left
                                by 8 is 256.
       LOCAL_DATA
                               DB ,
                               DW IMAGE_LEFT
                               DW IMAGE_TOP
                               DW IMAGE_WIDE
                               DW IMAGE_DEEP
                               DW LOCAL_FLAG_BYTE

IMAGE_WIDE and IMAGE_DEEP are what you would need.

This all seems complicated and I don't have much time mess with it but it comes from an older book called Bit-Mapped Graphics by Steve Rimmer (ISBN 0-8306-3558-0) The Copyright on the book I have is 1990 First Edition Six Printing.

They give examples in C and Assembly on how to decode a GIF as Well as BMP and TIFF Files.

0
 

Author Comment

by:VB-tinkerer
ID: 1427405
Thanks - I'll check that out later.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question