Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to read bytes in binary mode inserting in matrix

Status
Not open for further replies.

MarcoMB

Programmer
Oct 24, 2006
61
IT
After i've tried to update a vb 6.0 project to vb.net, using visual studio utility,i can't read correctly data bytes from a .bmp file to insert them in a matrix to operate on.

Using vb 6.0 the code was based on Get function:

GET #1, PIXELSTART, PHOTO.MATRIX

where PHOTO is a structure data type, with a member MATRIX previously defined in this way:

ReDim PHOTO.MATRIX(1 TO PHOTO.WIDTH*3,1 TO PHOTO.HEIGHT)

in this way,the program read bytes starting from PIXELSTART in bmp file and put them in transpose matrix resultant.
For example:
an image of 622*277 pixel has a matrix of 1868*277 bytes considering 24 bit depth and so 3 bytes per pixel.

With Get function the bidimensional array,the matrix, was filled correctly, as visible using debugger, with the single pixel value of the bitmap.

Using vb.net, the utility tansformed the code in this way:

ReDim PHOTO.MATRIX(PHOTO.WIDTH*3,PHOTO.HEIGHT)

FILEGET(1,PHOTO.MATRIX(PHOTO.WIDTH*3,PHOTO.HEIGHT),STARTPIXEL)

I know the fact that the array in enumerated in different ways in vb 6.0 and .net(start with 0 in net,with 1 in 6.0), but the big big problem is that THE MATRIX HERE IS FILLED WITH NOTHING!!!Every matrix value is equal to zero, and it result in a black image!
The dimensions of the bitmap however are read correctly from bmp file in this way:

FILEGET(1,WIDTH,19)

FILEGET(1,HEIGHT,23)

Some help please!!!






Con la funzione Get tutto filava liscio e l'array bidimensionale veniva
riempito correttamente come visibile dal debug con i valori dei singoli
pixel della bitmap.
Con l'upgrade a .Net il codice è stato così trasformato:

ReDim FOTO.MATRICE(FOTO.LARGHEZZA*3, FOTO.ALTEZZA)

FileGet(1, .g(FOTO.LARGHEZZA*3, FOTO.ALTEZZA),
INIZIOPIXEL)

Tralasciando il fatto che l'array è indicizzato diversamente dal 6.0 cioè
qui parte da ZERO e non da UNO, il problema è che nell'array non viene messo
alcun valore letto dal file numero 1, ovvero il valore di tutti gli elementi
della matrice e per ognuno = 0, risultato si ottiene una bitmap delle
dimensioni giuste,viste che precedentemente questi bytes vengono letti
correttamente sempre usando FileGet,ma tutta nera!
le dimensioni sono state correttamente recuperate:

FileGet(1, LARGHEZZA, 19) 'Width

FileGet(1, ALTEZZA, 23) 'Height
Qualcuno ha un'idea?
 
I'll be honest, I didn'y understand a word of the end of your post but I'd try
HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
sorry i didn't traduce all th question...i'm italian

After i've tried to update a vb 6.0 project to vb.net, using visual studio
utility,i can't read correctly data bytes from a .bmp file to insert them in
a matrix to operate on.

Using vb 6.0 the code was based on Get function:

GET #1, PIXELSTART, PHOTO.MATRIX

where PHOTO is a structure data type, with a member MATRIX previously
defined in this way:

ReDim PHOTO.MATRIX(1 TO PHOTO.WIDTH*3,1 TO PHOTO.HEIGHT)

in this way,the program read bytes starting from PIXELSTART in bmp file and
put them in transpose matrix resultant.
For example:
an image of 622*277 pixel has a matrix of 1868*277 bytes considering 24 bit
depth and so 3 bytes per pixel.

With Get function the bidimensional array,the matrix, was filled correctly,
as visible using debugger, with the single pixel value of the bitmap.

Using vb.net, the utility tansformed the code in this way:

ReDim PHOTO.MATRIX(PHOTO.WIDTH*3,PHOTO.HEIGHT)

FILEGET(1,PHOTO.MATRIX(PHOTO.WIDTH*3,PHOTO.HEIGHT),STARTPIXEL)

I know the fact that the array in enumerated in different ways in vb 6.0 and
.net(start with 0 in net,with 1 in 6.0), but the big big problem is that THE
MATRIX HERE IS FILLED WITH NOTHING!!!Every matrix value is equal to zero,
and it result in a black image!
The dimensions of the bitmap however are read correctly from bmp file in
this way:

FILEGET(1,WIDTH,19)

FILEGET(1,HEIGHT,23)

Some help please!!!
 
Is it worth a try in the forum I posted?

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
i don't understand... can you help me to find an answer?
 
HarleyQuinn was suggesting that the VB.NET forum may be a better place to ask your question:
forum796
 
Actually, the Italian in the original post is clearly the same as the English above it. The languages are close enough alike to piece that out.
 
I'll try to give more informations...

This is the structure:

Private Structure Photo
Dim PhotoName As String
Dim FormPhoto As frmFoto
Dim w As Integer
Dim w3 As Integer
Dim h As Integer
Dim StartPixel As Integer
Dim header() As Byte
Dim g(,) As Byte 'pixel matrix
End Structure


Then some declarations...

Dim Foto() As Photo
Dim nPhoto As Short

The load routine:

Private Sub LoadPhoto(ByVal PhotoName As String, ByVal Origin As Short)
Dim FormPhoto As Object
'carica Bitmap
Dim w As Integer
Dim h As Integer
Dim pixelOffset As Integer

With Photo(gCurrent)
.FormPhoto = New frmPhoto
.FormPhoto.Text = PhotoName
.FormPhoto.Tag = CStr(gCurrent) ' per associare il form alla foto
corrente
.FormPhoto.Show()
.PhotoName= PhotoName

If Origin = 0 Then ' must read from bmp file

Try
'Dim size As Size =
System.Drawing.Image.FromFile(PhotoName).Size
'.FormPhoto.picPhoto.Size = size
'.FormPhoto.picFoto.BackgroundImage =
System.Drawing.Image.FromFile(NomePhoto)

FileOpen(1, PhotoName, OpenMode.Binary)
'UPGRADE_WARNING: Get was upgraded to FileGet and has a
new behavior. Click for more:
'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
FileGet(1, pixelOffset, 11)
'UPGRADE_WARNING: Get was upgraded to FileGet and has a
new behavior. Click for more:
'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
FileGet(1, w, 19) 'Width
'UPGRADE_WARNING: Get was upgraded to FileGet and has a
new behavior. Click for more:
'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
FileGet(1, h, 23) 'Height
.w = w
.w3 = Multiple4(w * 3) 'width and height are read
correctly
.h = h
.StartPixel = 1 + pixelOffset


ReDim .header(pixelOffset - 1)
"'
FileGet(1, .header, 1)

ReDim .g(.w3, .h) 'transpose matrix


FileGet(1, .g(.w3 - 1, .h - 1), .StartPixel ) 'ERROR
HERE, matrix is filled with nothing,beginning read from StartPixel

FileClose(1)

End With
End Sub


This is the code... in vb.net forums nobody helps me so ... i hope someone here can make my program works
 
Why would anyone in the VB5/6 forums be able to help you better with a vb.net issue than people in the vb.net forums?
 
As strongm is saying (well, to expand on what he's saying), if it worked ok in VB6, and doesn't work in VB.Net, it's really a .Net issue. Probably something in one of the object libraries is behaving differently, and it's quite likely that someone over there will have run into this already.

Good Luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top