PDA

View Full Version : Invalid cast?



sandheep
August 13, 2005, 03:02:02
I'm writing a VB.net 2k3 app and am having problems with the image capture.

My app displays live images just fine from my Sony XCD-X710 camera.

When I run the sub below, I get the following error:

An unhandled exception of type 'System.InvalidCastException' occurred in Cleaving Capture.exe

Additional information: Specified cast is not valid.

Here is the sub:

Private Sub cmdCapture_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCapture.Click

Dim Buf As ICImagingControl.ImageBuffer
Buf = icMain.ImageActiveBuffer 'error on this line
Buf.SaveAsJpeg(lblFileName.Text, 100)

End Sub

Any ideas what would cause this error?

Thanks,

Sandheep

sandheep
August 13, 2005, 03:27:02
Whoops--Figured out the problem...should have used the following line instead while defining buf:

Dim bufTmp As TIS.Imaging.ImageBuffer

But...now a new problem. I am able to view a live image on my image control. However, when I capture it (using the code above), the resulting JPG is completely black.

Do I have to set imagebuffer parameters separately from the live image parameters (gain, exposure, etc)?

Any ideas?

Thanks,

Sandheep

Stefan Geissler
August 15, 2005, 09:21:05
Hello Sandheep,

If the saved image is completely black, then the image buffer is empty (completely zeroed out). You can not adjust the camera and video properties separately for the image.
You may should write

Set Buf = icMain.ImageActiveBuffer
instead of

Buf = icMain.ImageActiveBuffer
(This was Visual Basic 6.)
Also you should call icMain.MemorySnapImage. This captures an image from the live stream and saves it into the image buffer.