|
-
Sep 17th, 2000, 12:41 AM
#1
Thread Starter
Lively Member
How do you...
1) Find out if C:\myimage.bmp is 256 colors?
2) Find the dimensions of C:\myimage.bmp?
___________________________
Chris
-
Sep 17th, 2000, 07:44 AM
#2
_______
<?>
to get the dimensions:
add a picture box (invisible)
load the picture into the box
msgbox picture1.picture.width & " " & picture1.picture.height
unload the picture
I am not sure on this but I think jpg and gif are only
allowed 256. If that is so then knowing the ext will not tell you if they are 256 but will tell you if they are under.
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 17th, 2000, 07:58 AM
#3
Gif's are restricted to 256 colours maximum, and JPeg's must have at LEAST 256 colours, I think i got that right.
-
Sep 17th, 2000, 10:25 AM
#4
_______
<?>
Yup.
gif = 256 colors max
jpg = 16.7 million max
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 17th, 2000, 11:01 AM
#5
WHat's with you? Just go on the net, find the structure of a .BMP file header and read that info using: OPEN "blah.bmp" FOR BINARY AS hFile
and some reading commands... why the picturebox? Doesn't anyone care about using useless MEGABYTES of ram using useless dll's to do stuff you could also do the easy and efficient way?
Gerco Dries.
-
Sep 17th, 2000, 11:12 AM
#6
Thread Starter
Lively Member
VB has that screwy way of using weird things... the height and width of things ARENT pixels.
Also, BMPs may be 256 colors or not.. i want to find out how to see if they are. How do you view the header?
___________________________
Chris
-
Sep 17th, 2000, 12:08 PM
#7
Guru
VB's screwy way is called Twips.
Microsoft decided to use twips because, um, well, because... Nobody knows but Jesus. 
Anyway, I whipped up some code which sorta kinda lets you view the header of a BMP.
The error checking is minimal, but any more and it would have to be a BMP editor. 
Try!
Code:
Option Explicit
Enum eColors
clrInvalid = 0 ' Unknown
clrBlackWhite = 1 ' 1-bit, 2^1 = 2 colors (black and white)
clr16Colors = 4 ' 4-bit, 2^4 = 16 colors
clr256Colors = 8 ' 8-bit, 2^8 = 256 colors
clr16BitColor = 16 ' 16-bit, 65536 colors
clr24BitColor = 24 ' 24-bit, 16777216 colors
clr32BitColor = 32 ' 32-bit, many colors :rolleyes:
End Enum
Private Const MINIMUM_BMP_SIZE = 66 ' Believe it or not, 66 bytes
Private Const BMPID_WINDOWS = "BM"
Private Const BMPID_OS2BMP = "BA"
Private Const BMPID_OS2COLORICON = "CI"
Private Const BMPID_OS2COLORPOINTER = "CP"
Private Const BMPID_OS2ICON = "IC"
Private Const BMPID_OS2POINTER = "PT"
Private Const BMPHEADER_ID_POSITION = 1 ' The ID variable is at byte 1 of the file
Private Const BMPHEADER_WIDTH_POSITION = 19 ' The Width variable is at byte 19 of the file
Private Const BMPHEADER_HEIGHT_POSITION = 23 ' The Height variable is at byte 23 of the file
Private Const BMPHEADER_COLORS_POSITION = 29 ' The Colors variable is at byte 29 of the file
Function GetBitmapData(ByVal sFileName As String, lWidth As Long, lHeight As Long, BmpColors As eColors) As Boolean
Dim btFileNum As Byte, sID As String, iColors As Integer
On Error Resume Next
btFileNum = FreeFile
Open sFileName For Binary Access Read As btFileNum
' Could open file? Exit Sub
If Not Err.Number = 0 Then Exit Function
' Minimal error checking:
' 1) Must be a valid file size
If LOF(btFileNum) < MINIMUM_BMP_SIZE Then Exit Function
' 2) Must be a valid 2-byte ID
sID = vbNullChar & vbNullChar ' Allocate 2 bytes
Get btFileNum, BMPHEADER_ID_POSITION, sID ' Retrieve 2 bytes from file
' Check if the 2 bytes are valid
If Not ((sID = BMPID_WINDOWS) Or (sID = BMPID_OS2BMP) Or (sID = BMPID_OS2COLORICON) Or _
(sID = BMPID_OS2COLORPOINTER) Or (sID = BMPID_OS2ICON) Or (sID = BMPID_OS2POINTER)) _
Then Exit Function
' Get Width and Height variables
Get btFileNum, BMPHEADER_WIDTH_POSITION, lWidth
Get btFileNum, BMPHEADER_HEIGHT_POSITION, lHeight
' Get Colors variable
Get btFileNum, BMPHEADER_COLORS_POSITION, iColors
' Check if the color is valid, looks ugly but works!
BmpColors = IIf((iColors = clrBlackWhite) Or (iColors = clr16Colors) Or _
(iColors = clr256Colors) Or (iColors = clr16BitColor) Or (iColors = clr24BitColor) _
Or (iColors = clr32BitColor), iColors, clrInvalid)
Close btFileNum
GetBitmapData = True ' Success
End Function
Then you could use something like...
Code:
Private Sub Form_Load()
Dim lWidth As Long, lHeight As Long, BmpColors As eColors, bResult As Boolean
Const sFileName = "C:\Windows\Clouds.bmp"
bResult = GetBitmapData(sFileName, lWidth, lHeight, BmpColors)
If bResult Then
Call MsgBox(sFileName & vbCrLf & "Width: " & lWidth & " pixels." & vbCrLf & _
"Height: " & lHeight & " pixels." & vbCrLf & "Colors: " & BmpColors & " bits.", _
vbInformation)
Else
Call MsgBox(sFileName & vbCrLf & "Could not get file information." & vbCrLf & _
"Either there was a problem opening the file, or its format is invalid.", _
vbCritical)
End If
End Sub
-
Sep 17th, 2000, 02:02 PM
#8
_______
<?>
Gerco...*&^% %^$
With todays systems who cares about the overhead of a picture box...look what the result of y2k was because someone wanted to save the 2 characters.
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 17th, 2000, 02:50 PM
#9
Thread Starter
Lively Member
Thanks! That helped alot!! And I didnt know they were called "Twips", I learned something new !! YAYAYAYAY! Wowowowowoowwoowo
d00dz!!! i l3ar|\|3|> s0m371n9 n3\/\/!!1 1337!!
___________________________
Chris
-
Sep 17th, 2000, 04:22 PM
#10
Thread Starter
Lively Member
Another quick question. Would It be possible to edit the header, and add a description section? I.e. so when you load an image, it will load its description!? thanks...
___________________________
Chris
-
Sep 18th, 2000, 08:22 AM
#11
-
Sep 18th, 2000, 01:59 PM
#12
I could of course tell you that the .BMP format doesn't provide for descriptions. I could also tell you to store the description in the image itself (in the pixels). That's also a cool way to store data you don't want anyone to see. Noone will ever look for it IN an image.
But then ppl would just ***** on me for wanting to be efficient. And conserving memory by NOT using a generally useless picturebox is something completely different than assuming years will not go past 2000!
This picturebox's only use would be to find out the width and height of a .bmp image, when it also has other uses (like displaying said image) then it's use would have been useful. In this particular instance, it would just be a wate of resources AND it's a LOT slower than just reading the header and it's not any more flexible (quite the opposite actually).
Not all ppl use 900Mhz computers... there are still ppl (about 60% of computer users) who work on 233Mhz or lower!
Gerco Dries.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|