Recover data from a bitmap and filling a matrix

M

Marco Biagioni

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!!!
 
T

Tom Shelton

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!!!

Can you give us a complete snipit of code - along with the declaration
of any structures/arrays etc.
 
M

Marco Biagioni

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top