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!

Recover data from a bitmap and filling a 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!!!
 
So, what is your question?

-The answer to your problem may not be the answer to your question.
 
Maybe i could not be clear with my question... my code is

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


My error is about filling the matrix reading data from bitmap...as i said my matrix is filled with all zero values, result in a black image, instead read correctly pixel values from bmp.
In vb 6.0 it worked all right...this is my problem and my question...why in .Net it doesn't work?
 
1.) have you tried with a different picture, for verification, that there isnt something "funny" about the picture you are using.

2.) have you verified that the file is opened after you use fileOpen? I do not see any sort of checking.

3.) are the values what they should be when you stop, with the debugger at the FileGet(1, .g(.w3 - 1, .h - 1), .StartPixel ) 'ERROR



-The answer to your problem may not be the answer to your question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top