|
-
Mar 29th, 2001, 03:31 AM
#1
Thread Starter
New Member
Hi buddies:
I wanna write a program in Visual Basic which can read a BMP file and convert it into a Matrix... can anybody have any idea or experience about this.. Help me.. i will really appreciate it..
Thank you,
Farshid
-
Mar 29th, 2001, 03:55 PM
#2
Good Ol' Platypus
Like a matrix of RGB values?
(make sure to define GetPixel as in API Viewer...) 
(hehe, he called me a buddy ) - thanks man, means the world to me *sob* 
j/k 
Code:
Dim hMat() as RGBT
Type RGBT
R as Single
G as Single
B as Single
End Type
Function GetR(ByVal pCol As Long) As Byte
GetR = pCol Mod 256
End Function
Function GetG(ByVal pCol As Long) As Byte
pCol = pCol \ 256
GetG = pCol Mod 256
End Function
Function GetB(ByVal pCol As Long) As Byte
pCol = (pCol \ 256) \ 256
GetB = pCol Mod 256
End Function
Sub ConvertToMatix(hDC as Long, W, H, hMatrix as RGBT)
dim TEMP as Long
Redim hMatrix(0 to W, 0 to H) as RGBT
Dim I, J
For I = 0 to W
For J = 0 to H
TEMP = GetPixel(hDC, I, J)
hMatrix(I, J).R = GetR(TEMP)
hMatrix(I, J).G = GetG(TEMP)
hMatrix(I, J).B = GetB(TEMP)
Next J
Next I
End Sub
'usage:
ConvertToMatrix Pic1.hDC, Pic1.ScaleWidth, Pic1.ScaleHeight, hMat
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Mar 29th, 2001, 10:34 PM
#3
Thread Starter
New Member
Further explanation
Hi budy Sastraxi:
Thank you very much for the help... I am a beginner in Visual Basic Programming for Graphics.. The assignment that i have been given is that i should develop a program or rather a function which should open a bmp file, read it and convert save the image data in a matrix. So this is all what i want. can u help me in this regard. I will be really thankful to you for it..
bye..
Farshid
-
Mar 29th, 2001, 11:18 PM
#4
Good Ol' Platypus
hmmm.. i thought i posted what you wanted....
Ah well, please explain what you want to DO with this "matrix" after you have gathered the data (if not in the way i showed then what?)
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Mar 29th, 2001, 11:22 PM
#5
Good Ol' Platypus
if you cant explain it well here drop me an email:
[email protected]
And check out my soon-to-be website:
http://vbden.com-1.net/
-or-
http://vbden.tripod.com/
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Mar 30th, 2001, 02:51 AM
#6
Thread Starter
New Member
Here is my problem
Hi budy...
Here is my problem.
I want to write a program which can can input bmp image (Black and white colors only) and then read the bmp file... save the image information in a matrix (array) and then store the matrix in a file...
this is the whole problem.. i am really working hard on it.. ur cooperation will be highly appreciated buddy...
thanks for everything...
farshid
-
Mar 30th, 2001, 03:55 PM
#7
Good Ol' Platypus
Allright! Use the above code and the usage line to convert to an array. The above code will work for 24-bit colour bitmaps. Anyways, then, once you have the array:
Code:
Function StoreMatrix(hMatrix as RGBT, FileName as String)
Dim bI, bJ, I, J
bI = Ubound(hMatrix, 1)
bJ = Ubound(hMatrix, 2)
Open FileName for Input as #1
For I = 0 to bI: For J = 0 to bJ
Put #1, CSTR(SplitColours(hMatrix(I, J))
Next I: Next J
Close #1
End Function
Function OpenMatrix(hMatrix as RGBT, FileName as String)
Dim bI, bJ, I, J
Dim tMatrix() as Long
bI = Ubound(hMatrix, 1)
bJ = Ubound(hMatrix, 2)
Redim tMatrix(0 to bI, 0 to bJ) as Long
Open FileName for Output as #1
For I = 0 to bI: For J = 0 to bJ
Get #1, tMatrix(I, J)
hMatrix(I, J).R = GetR(tMatrix(I, J)
hMatrix(I, J).G = GetG(tMatrix(I, J)
hMatrix(I, J).B = GetB(tMatrix(I, J)
Next I: Next J
Close #1
End Function
Function SplitColours(Ins as RGBT) as Long
SplitColours = RGB(Ins.R, Ins.G, Ins.B)
End Function
Just make sure to dimension the array properly when loading the file. (OpenMatrix)
USAGE:
[code]
Dim hMat() as RGBT
ConvertToMatrix hMat, 20, 20, Picture1.hDC
StoreMatrix hMat, "C:\MyMat.XXX"
...
Dim myMat(20, 20) as RGBT
OpenMatrix myMat, "C:\MyMat.XXX"
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Mar 30th, 2001, 09:11 PM
#8
Thread Starter
New Member
Thanks
Hi friend:
Thank you very much for your help. I will study the code and see whether i will be able to solve my problem with it or not.. but hopefully i will... if anything i will just mail u..
ok..thanks alot once again for ur cooperation...
farshid
-
Apr 1st, 2001, 03:54 AM
#9
transcendental analytic
I don't get it, the bmp file format contains this "matrix" already.
-
Apr 1st, 2001, 09:44 AM
#10
Good Ol' Platypus
I think he wants to write it in plain text, so you could open it by just line inputting and saving that value in a pixel, until the end of file.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Apr 1st, 2001, 10:14 AM
#11
transcendental analytic
eh, i thought he refered to an 2darray with "matrix"
-
Apr 1st, 2001, 11:17 AM
#12
Good Ol' Platypus
Well If you look at the code I posted then you will see that it is both.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Apr 4th, 2001, 08:22 PM
#13
Addicted Member
I am not sure if I get this
By taking a quick look on the first part of the code (posted by Sastraxi), I understand you split the three components of the BMP image.
However, this is done using a handle to a picture control, isn't it ?? ( ConvertToMatrix Pic1.hDC, Pic1.ScaleWidth, Pic1.ScaleHeight, hMat )
Can this be done by reading the bitmap as a BINARY FILE directly ? Do you know the binary format of the BMP files ?
-
Apr 4th, 2001, 09:01 PM
#14
Good Ol' Platypus
You could load it, make a compatible DC with the DIB data, and then call the DC in along with the array and the height and width in the DIB Type structure.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Apr 4th, 2001, 09:12 PM
#15
Addicted Member
-
Apr 5th, 2001, 03:21 AM
#16
Fanatic Member
http://rookscape.com/vbgaming/tutAX.php
This tutorials shows you two things, first of all how to load the bitmap data into UDTs and an array, and secondly how to use that data directly to blit the bitmap to a DC...
You can easily pick out the first part though, which shows how the bitmap format is put together...
Teaudirenopossum.Musasapientumfixaestinaure.
(I can't hear you. There's a banana in my ear)
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
|