P
Pete Davis
I've got an app that plays video using the ActiveMovie COM stuff.
I'm using the FilgraphManagerClass to play the movie and I'm trying to get
an image from the currently displayed scene.
The call to do it is FilgraphManagerClass.GetCurrentImage(ref int
bufferSize, out int dibImage)
Now, I'm aware that my code, as-is, might not free what it's allocating.
That's okay for the moment. I just want to get it working first, then I'll
get it working cleanly.
unsafe private byte[] GetImageData()
{
byte[] buffer = null;
try
{
int buffSize = 0;
int zero = 0;
fmc.GetCurrentImage(ref buffSize, out zero);
IntPtr tempBuffer = Marshal.AllocHGlobal(buffSize);
int tempBufferInt = tempBuffer.ToInt32();
fmc.GetCurrentImage(ref buffSize, out tempBufferInt);
buffer = new byte[buffSize];
Marshal.Copy((IntPtr) tempBufferInt, buffer, 0, buffSize);
Marshal.FreeHGlobal((IntPtr) tempBufferInt);
}
catch(System.Exception ex)
{
Debug.WriteLine(ex.Message);
}
return buffer;
}
Calling GetCurrentImage with zero for the dibImage, should set the buffSize.
This does not happen, however.
If I skip that first call to GetCurrentImage and instead set buffSize to
say, 10*height*width (which should be more than enough room to store the
image), then on the call to GetCurrentImage causes my application to exit.
No exceptions, no messages in the debug output, the app just ends.
Any ideas?
Pete
I'm using the FilgraphManagerClass to play the movie and I'm trying to get
an image from the currently displayed scene.
The call to do it is FilgraphManagerClass.GetCurrentImage(ref int
bufferSize, out int dibImage)
Now, I'm aware that my code, as-is, might not free what it's allocating.
That's okay for the moment. I just want to get it working first, then I'll
get it working cleanly.
unsafe private byte[] GetImageData()
{
byte[] buffer = null;
try
{
int buffSize = 0;
int zero = 0;
fmc.GetCurrentImage(ref buffSize, out zero);
IntPtr tempBuffer = Marshal.AllocHGlobal(buffSize);
int tempBufferInt = tempBuffer.ToInt32();
fmc.GetCurrentImage(ref buffSize, out tempBufferInt);
buffer = new byte[buffSize];
Marshal.Copy((IntPtr) tempBufferInt, buffer, 0, buffSize);
Marshal.FreeHGlobal((IntPtr) tempBufferInt);
}
catch(System.Exception ex)
{
Debug.WriteLine(ex.Message);
}
return buffer;
}
Calling GetCurrentImage with zero for the dibImage, should set the buffSize.
This does not happen, however.
If I skip that first call to GetCurrentImage and instead set buffSize to
say, 10*height*width (which should be more than enough room to store the
image), then on the call to GetCurrentImage causes my application to exit.
No exceptions, no messages in the debug output, the app just ends.
Any ideas?
Pete