Sign in to follow this  
Followers 0
DK12000

VB6 ReDim to create buffer size for file export

4 posts in this topic

I am working on a little pet project with a CCTV manufactures SDK and have had no problems right up to the point were I'm trying to save a .bmp from the camera stream, they use this as the VB6 example (obviously just the file export bit) :

Private Sub Export_Click()
Dim result As Long
Dim imagebuffer() As Long
Dim mydate As Date
Dim mysector As Long
Dim mycamera As Long
Dim image_width As Long
Dim image_height As Long

' Allocate a buffer big enough to contain a "image_width"x"image_height" pixels bitmap at 24bit color depth (+54 bytes of BMP header).
XXXX.GetResolution window, image_width, image_height
ReDim imagebuffer((54 + image_width * image_height * 3 - 1) \ 4)
' ---- Get bitmap of video from the specified connection/camera.
mycamera = 0 ' camera number [0..N]
result = XXXX.ConvertImageToBitmapWin(imagebuffer(0), mydate, mycamera, window, connection, image_width, image_height)
If (result <> 1) Then
MsgBox "Image export failed, code: " & result
Else
' ---- Save bitmap to file.
Dim FileName As String
Dim FileNum As Long
FileName = InputBox("Enter target image filename")
If (FileName <> "") Then
FileNum = FreeFile
Open FileName For Binary As #FileNum
Put #FileNum, , imagebuffer
Close #FileNum
End If
End If
End Sub

As you can see they pre-allocate a buffer to hold the data, this has been doing my head in as they appear to be using an array to do it by creating the number of elements required to be a certain byte count ?

I've tried DllStructCreate and _MemGlobalAlloc but keep getting Type mismatch COM errors. If someone could point me in the right direction and save my poor spongy head I would be indebted.

Share this post


Link to post
Share on other sites



It seems that you want to save an image. If you have the handle of the image you can use GDI+ to save it to the disk.

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

I feel like I've been visited by the comedy gods, love the avatars :)

Sorry I didn't explain very well.

In that example they use the SDK object to query the camera that's being displayed and return the height and width of the image.

XXXX.GetResolution window, image_width, image_height

They then do a calculation to get the file size and use the result to create an array :

ReDim imagebuffer((54 + image_width * image_height * 3 - 1) 4)

I get the width (2048) and height (1536) and using that calculation get a result of 2359309

The ConvertImageToBitmapWin needs a pre defined buffer to write the image information into before it can be written to a file.

In the VB example its imagebuffer(0) which was the array created earlier.

XXXX.ConvertImageToBitmapWin(imagebuffer(0), mydate, mycamera, window, connection, image_width, image_height)

I have tried creating a file and passing ConvertImageToBitmapWin a file handle, no good.

I created a Struct and passed that still no go :

$str = "BYTE var1[2359309]"  ; (I also tried LONG)
$a = DllStructCreate($str)
If @error Then
    MsgBox(0, "", "Error in DllStructCreate " & @error);
    Exit
EndIf
XXXX.ConvertImageToBitmapWin(DllStructGetPtr($a,"var1"), $mydate, $mycamera, $window, $connection, $image_width, $image_height)

I even tried just creating the Array[2359309] and writing to it but same Type mismatch error.

So I'm stymied...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0