PDA

View Full Version : IC ActiveX Imaging Control under .NET



Unregistered
August 16, 2002, 08:28:47
Hi all,

I've attempted to use the ActiveX Imaging Control in a VB .NET project as per the "First Steps" section in the "Visual Basic User's Guide" from "IC Imaging Control ActiveX Programmer's Guide", but encountered immediate problems.

Specifically, the "Device", "Input Channel", "Video Norm" and "Video Format" properties are not available, and if the LiveStart() method is called in the form's OnLoad() method, a System.Runtime.InteropServices.COMException gets thrown with a HRESULT of 0x800A000C. I assume the actual error's not that important as the above properties were never set in the first place (as they seem to be unavailable under Visual Studio .NET).

I would greatly appreciate any advice indicating whether the problems are due to the fact that I'm not doing something obvious, or whether the ActiveX control is not yet supported under .NET.

thanks in advance,
Graeme


This message was originally posted by Graeme Spears in the old IC Imaging Control Support Forum.

Unregistered
August 20, 2002, 10:00:24
Hello,

please refer to

http://www.imagingcontrol.com/ic/support/forum/read.php?f=2&i=337&t=332

Best regards
Stefan
IC Support


This message was originally posted by Stefan in the old IC Imaging Control Support Forum.

Unregistered
August 23, 2002, 01:33:27
Stefan,

Thanks for the response.

I was certainly aware of the contents of the original posting, but the gist of this posting, "You could use the ActiveX Control in VC. NET. This will work without problems.", did not turn out to be the case. I did not find that the ActiveX control worked under .NET without any problems.

As I indicated above, under .NET I found that several properties of the ActiveX control were unavailable. Any other suggestions would be greatly appreciated.

best regards,
Graeme Spears


This message was originally posted by Graeme Spears in the old IC Imaging Control Support Forum.

Unregistered
August 23, 2002, 10:03:00
Graeme,

You are right.

The IC Imaging Control ActiveX is usable with limitaions in Visual Basic .NET.
The property browser of Visual Basic.NET can not display and set all properperties of IC Imaging Control. This results in setting the properties in the program code.
Another limitation is, that the method GetImageData() will not work correctly. A workaround is not available at this moment.
The Visual Basic examples of IC Imaging Control can not be used in Visual Basic .NET, because Visual Basic .NET has other event handling and other language elements.
It is possible to display the live video image, save frames to harddisk and capture avi files with IC Imaging Control ActiveX using Visual Basic .NET.

Best regards
Stefan
IC Support


This message was originally posted by Stefan in the old IC Imaging Control Support Forum.

Unregistered
December 2, 2002, 22:49:25
Hello!

Has this issue been addressed since the time this topic was originally started?

I am in a similar situation trying to get the OCX to run under C# (.NET) and I am getting the same error message (with same code 0x800A000C).

Please let me know whether there is any way to grab individual frames to memory within a .NET application.

Thanks in advance...

Mathieu.


This message was originally posted by Mathieu Frenette in the old IC Imaging Control Support Forum.

Ernest
April 27, 2004, 18:35:53
Hello,
I'm trying to use the IC Imaging Control ActiveX in C# and so far I can get it to display live video and draw text and lines on live video, but there are a few issues:
1. OverlayUpdate event sometimes (few times per minute) returns invalid Font property, so when I attempt to use it to save the current font, the whole app is crashing with SystemExecutionException. The only workaround is to use same font everywere and not to save/load it dynamically.
2. It appears that there is a memory leak, because after running for some time (2-3 minutes) OverlayBitmap.DrawLine method in the OverlayUpdate event handler fails with OutOfMemoryException in stdole.IPicture (OverlayBitmap.Picture property). This issue appeared only after Iset LiveCaptureContinuous = true. If I catch this exception and run for a while, the whole app is crashing with OutOfMemory Exception. We probably have to release the OverlayBitmap object explicitly.
3. ImageAvailable event doesn't fire even after I set LiveCaptureContinuous = true, therefore I could not get a bitmap from the buffer using this event.

Any ideas?

BTW, is there a sample code in .NET? How is the .NET support coming alone?

Ernest
April 28, 2004, 02:51:50
One more note on using the ActiveX in .NET:

I'm trying to do graphic overlay in C# following your VB example code. It executes without any errors, but nothing appears on the video... Any ideas?
__________________________________________________ ________

// Here is my GDI Functions declaration:

[DllImport("gdi32.dll")]
static extern IntPtr CreateCompatibleDC(IntPtr hdc);

[DllImport("gdi32.dll")]
static extern bool DeleteDC(IntPtr hdc);

[DllImport("gdi32.dll")]
static extern bool BitBlt(IntPtr hdc, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop);

[DllImport("gdi32.dll")]
static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);

uint SRCCOPY = 13369376;

// And here is my implementation of the function:

private void ShowBitmap()
{
stdole.IPicture Pic = new stdole.StdPictureClass();
int PicWidth = 0;
int PicHeight = 0;
ICImagingControl.OverlayBitmap ob;
IntPtr obDC;
IntPtr SourceDC;
int Col = 0;

if(vid.DeviceValid)
{
if(vid.LiveVideoRunning)
{
ob = vid.OverlayBitmap;

// Load a BMP file. pic is PictureBox control, already placed on the form
pic.Image = Image.FromFile(@"C:\Temp\test.bmp");

// Get the size of the picture in pixel units.
PicWidth = pic.Image.Width;
PicHeight = pic.Image.Height;

// Calculate a column to display the bitmap in the upper right corner
// of Imaging Control.
Col = vid.Width - 5 - PicWidth;

// Get the DC of the OverlayBitmap object.
obDC = (IntPtr)ob.GetDC();
if(obDC.ToInt32() != 0)
{
// Create a compatible DC that is used to hold the loaded bitmap.
SourceDC = CreateCompatibleDC(obDC);
if(SourceDC.ToInt32() != 0)
{
// Select the loaded bitmap in the source DC.
SelectObject(SourceDC, (IntPtr)Pic.Handle);

// Now blit the source DC in the overlay bitmap DC.
// This copies the loaded bitmap to the overlay bitmap.
BitBlt(obDC, Col, 5, PicWidth, PicHeight, SourceDC, 0, 0, SRCCOPY);

// Delete the DC source that is no longer needed to avoid handle leaks.
DeleteDC(SourceDC);
}
// Release the DC.
ob.ReleaseDC(obDC.ToInt32());
}
}
}
if (pic.Image != null)
{
pic.Image.Dispose();
pic.Image = null;
}
Pic = null;
ob = null;
}

Stefan Geissler
April 28, 2004, 07:46:32
Hello Ernest,

You should use vid.ImageWidth instead of vid.Width to calculate your starting col.
If there is not any other graphic like lines or text on the overlay, make sure you have enabled the overlay.
If would be a help for me, if you could send the project to support@imagingcontrol.com in the case, the bitmap stays not visible.

Ernest
April 28, 2004, 23:43:18
For those who are curious about a working solution in C# for displaying a bitmap... see the code above for reference and replace it with the following:

// Get the DC of the OverlayBitmap object.
obDC = (IntPtr)ob.GetDC();
if(obDC.ToInt32() != 0)
{
// Create a compatible DC that is used to hold the loaded bitmap.
SourceDC = CreateCompatibleDC(obDC);
if(SourceDC.ToInt32() != 0)
{
// Select the loaded bitmap in the source DC.
//SelectObject(SourceDC, (IntPtr)Pic.Handle);

// Now blit the source DC in the overlay bitmap DC.
// This copies the loaded bitmap to the overlay bitmap.
//BitBlt(obDC, Col, 5, PicWidth, PicHeight, SourceDC, 0, 0, SRCCOPY);

Graphics g = Graphics.FromHdc(obDC, SourceDC);
g.DrawLine(Pens.YellowGreen, vid.Width/2, vid.Height/2 , vid.Width, vid.Height);
g.DrawImage(pic.Image, Col, 5, PicWidth, PicHeight);

g.Dispose();

// Delete the DC source that is no longer needed to avoid handle leaks.
DeleteDC(SourceDC);
}
// Release the DC.
ob.ReleaseDC(obDC.ToInt32());
}

Stefan Geissler
April 29, 2004, 08:06:24
Ernest,

When debugginh your code, i found Pic.Handle was zero. I used following code to load the bitmap:
[code]
Bitmap TheImage ;
TheImage = new Bitmap(@"C:\Test\c#\ICImagingTest\ICImagingTest\hardware.bm p");

The Bitmap class gives me an HBITMAP.

I think, your suggestion to use the C# system.drawing is a much safier way to blit the bitmap on the overlay.

Ernest
April 30, 2004, 02:02:25
Dear Stefan,
Thank you so much for your help!

Here is the list of other issues/questions, which I haven't been able to find the answers yet:

1. If LiveCaptureContinuous = true, then calling vid.MemorySnapImage() method generates the following error:
Exception from HRESULT: 0x800A000B (CTL_E_DIVISIONBYZERO)
According to the SDK it should do nothing.

2. Call to vid.MemorySaveImage(file) works fine and it actually saves the bitmap with graphic overlays. Is there a way to optionally save it without graphics?

3. Call to vid. MemorySaveImageSequence(num, file) fails with "The parameter is incorrect." error, if num > 5.

4. Is there a way to tell VMR to go into full-screen mode? Or maybe your control provides a method for switching to a full-screen mode (without the Windows form around the video)?

5. Apparently there is a memory leak somewhere in a control. Just running it with calling LiveStart() method with LiveCaptureContinuous = false (without processing any events) and monitoring the process memory indicates that there is a noticeable increment in memory usage.

6. While vid.DeviceFlipVerticalAvailable and vid.DeviceFlipHorizontalAvailable return true, setting properties vid. DeviceFlipVertical=true or vid.DeviceFlipHorizontal=true causes crash with the following error: "Exception from HRESULT: 0x800A0013"

7. Is there a way not to enforce normalized video aspect ratio? What do I need to do to fill all control area with live video? Zoom control is nice, but if the control's width/height aspect ratio does not precisely match ImageWidth/ImageHeight aspect ratio, then the empty space looks really bad on the screen. It would be nice to be able to set Image Width and Height independently or to have a way to fill the control's client area automatically on control's resize.

Stefan Geissler
April 30, 2004, 07:32:36
Hello Ernest,

>1. If LiveCaptureContinuous = true, then calling vid.MemorySnapImage()
>method generates the following error:
>Exception from HRESULT: 0x800A000B (CTL_E_DIVISIONBYZERO)
>According to the SDK it should do nothing.
To be tested. But the excetption occurs, because memorsnapimage runs automatically while
LiveCaptureContinuous is set to true. Therefore an application should be able to avoid this
exception.

>>2. Call to vid.MemorySaveImage(file) works fine and it actually saves the
>bitmap with graphic overlays. Is there a way to optionally save it without
>graphics?
No, except the overlay is disabled for this. We had a nearly similar thread in the forum.


>3. Call to vid. MemorySaveImageSequence(num, file) fails with "The parameter
>is incorrect." error, if num > 5.
This is, because the ImageRingbufferSize is set to 5 by default. If you want to snap more images in
a sequence, raise the ImageRingbufferSize.

>4. Is there a way to tell VMR to go into full-screen mode? Or maybe your
>control provides a method for switching to a full-screen mode (without the
>Windows form around the video)?
No.

>5. Apparently there is a memory leak somewhere in a control. Just running
>it with calling LiveStart() method with LiveCaptureContinuous = false
>(without processing any events) and monitoring the process memory indicates
>that there is a noticeable increment in memory usage.
This is to be tested. There was a similar problem reported with VC6, but after checking the
customers project, the memory leak was in his project. As mentioned, IC Imaging Control is written
for VB 6 and VC 6. The memory management in .NET differs from these platforms, so contraindications
are unpredictable. For example GetImageData gives you access to the image data, but after this,
they are deleted.

>6. While vid.DeviceFlipVerticalAvailable and
>vid.DeviceFlipHorizontalAvailable return true, setting properties vid.
>DeviceFlipVertical=true or vid.DeviceFlipHorizontal=true causes crash with
>the following error: "Exception from HRESULT: 0x800A0013"
To be tested.

>7. Is there a way not to enforce normalized video aspect ratio? What do I
>need to do to fill all control area with live video? Zoom control is nice,
>but if the control's width/height aspect ratio does not precisely match
>ImageWidth/ImageHeight aspect ratio, then the empty space looks really bad
>on the screen. It would be nice to be able to set Image Width and Height
>independently or to have a way to fill the control's client area
>automatically on control resize.
This is possible. Set LiveDisplay to false. Then you can control the width and height of the live
video:
.LiveDisplayDefault = False
' Set the width and height of the live video display to
' the width and height of IC Imaging Control. Now, the
' live video image fits into IC Imaging Control's window.
.LiveDisplayHeight = .Height
.LiveDisplayWidth = .Width

John Mcnaboe
May 11, 2004, 12:58:40
Hi

You said it should be possible to display video and grab images using VB.net. What changes would you need to make to the grabber sample for example to allow it to work.

Jmcn

Stefan Geissler
May 13, 2004, 07:21:06
Hi John,

Your question sounds simple and the answer sounds simple too. Just rewrite the complete sample manually. Automatic convertion will not work. Therefore the conversion of the VB DemoApp sample to VB.NET is quite a lot of manual work.

TimingMachinery
December 17, 2006, 15:15:11
I'm a beginner at IC Image Control Professional 3.0. I am running an XP Pro box with Visual Studio.net 2003 (Academic). My goal is a standalone windows application that has two functions (a) real-time video preview in a resizable window (scales the image), and (b) pushing a button leaves a bitmap file (e.g., .jpg) in a specified (or default) directory. A counter in the filename of the bitmap file should increment automatically, so that a series of bitmaps will be accumulated. (There should be a button to reset the counter to 0.) (I may add other functionality to the picture-taking button later.) A post some while back started with

"I've attempted to use the ActiveX Imaging Control in a VB .NET project as per the "First Steps" section in the "Visual Basic User's Guide" from "IC Imaging Control ActiveX Programmer's Guide", but encountered immediate problems."

I did not get as far as the author of that post, since when I tried to follow the "First Steps" I was immediately hit with "you do not have a license to use this ActiveX control" exception while trying to create an instance of TIS.Imaging.ICImagingControl. Please advise.

Stefan Geissler
December 18, 2006, 08:56:41
Dear Timing Machinery,

I saw that there is a similar post in the .NET forum at
http://www.theimagingsourceforums.com/showthread.php?t=319437
Thus I would like to continue there.