[Windows Mobile]Stilling images from Camera C# or DirectShow .NETCF part III

Ok, most popular question for last week was: “How to still images from windows mobile camera?”
I finished my project little bit earlier that i was planing, so i have free time again and looking for job too :)

So what do we need? tons extra com interfaces (Ipin, IEnumPins, IEnumFilters, IFileSinkFilter, IAMVideoControl and so on).

Also i implemented 2 useful classes (as for me) CPinList and CFilterList (the same as in DSPack).

public class CFilterList
{
private List<IBaseFilter> Filters;
private IEnumFilters enumFilters = null;
public CFilterList()
{
Filters = new List<IBaseFilter>();
}
~CFilterList()
{
Free();
Filters = null;
}
public void Assign(IGraphBuilder fg)
{
Clear();
fg.EnumFilters(out enumFilters);
IBaseFilter Filter;
int fetched = 0;

while (enumFilters.Next(1, out Filter, out fetched) == 0)
{
Filters.Add(Filter);
}

Marshal.ReleaseComObject(enumFilters);
enumFilters = null;
}
public int Count
{
get
{
return Filters.Count;
}
}
public IBaseFilter this[int index]
{
get
{
return Filters[index];
}
}
public void Free()
{
Clear();
}
private void Clear()
{
while (Filters.Count > 0)
{
Marshal.ReleaseComObject(Filters[0]);
Filters[0] = null;
Filters.RemoveAt(0);
}

Filters.Clear();
}
}

public class CPinList
{
private List<IPin> Pins = null;
private IEnumPins enumPins = null;

public CPinList()
{
Pins = new List<IPin>();
}

~CPinList()
{
Free();
Pins = null;
}

public int Count
{
get
{
return Pins.Count;
}
}

public IPin this[int index]
{
get
{
return Pins[index];
}
}

public void Assign(IBaseFilter filter)
{
Clear();
filter.EnumPins(out enumPins);

IPin pin;
int fetched = 0;

while (enumPins.Next(1, out pin, out fetched) == 0)
{
Pins.Add(pin);
}

Marshal.ReleaseComObject(enumPins);
enumPins = null;

}

private void Clear()
{
while (Pins.Count > 0)
{
Marshal.ReleaseComObject(Pins[0]);
Pins[0] = null;
Pins.RemoveAt(0);
}
Pins.Clear();
}

public void Free()
{
Clear();
}
}

so now stilling images works, btw in the same time with preview, but there some bad news (if we can call it so):
a) it takes like 15 seconds to build graph :(
b) when i still image preview hangs for like 2 seconds.

good news:
a) we can implement samplegrabber filter and do not wait when stilling images and building graph
b) filter of video capture device has 3 output pins (on my device), i`m not sure, but seems like: preview, still image and probably still video :) will try to check it soon

And last one perhaps preview and stilling images wont work on some devices in the same time so you will need to choose what exactly you need (but this is only unconfirmed “perhaps”)

Almost forgot

14 Responses to “[Windows Mobile]Stilling images from Camera C# or DirectShow .NETCF part III”

  1. 1
    josh apelbaum Says:

    hi Alex, awesome articles/sources, thanks!

    I’m looking for away to overlay a video with text or image (becuase VMR is not available for windows mobile)
    hopefully you or anyone else around can drop me a clue about it

    thanks

  2. 2
    Toyin Says:

    How can one improve on the resolution?

  3. 3
    Toyin Says:

    Secondly, the paint event doesn’t fire. I’m trying to create a target area, so that I can narrow the focus on the image. I’m guessing it has something to do with the run method, holding the panel to ransom. How can one solve this problem?

  4. 4
    James Says:

    Fantastic work
    Some day you plan to do video capture and video streaming?

  5. 5
    admin Says:

    2 josh apelbaum, you need to implement transfor filter or TranceInPlace
    2 James, perhaps, dont know yet, what to do next :)
    2 Toyin, resolution maybe will explaine in next article, paint event aint easy but possible, have to check first

  6. 6
    Toyin Says:

    Another cool thing to have perhaps, might be the ability to zoom in and out before taking the picture.

  7. 7
    admin Says:

    digital zoom in/out you can do using IVideoWindow, thats not a problem

  8. 8
    KenG Says:

    Tested DirectShowNETCF.dll on Motorola MC55 works great. Look forward to testing future versions with ability to enumerate/set resolutions (IAMStreamConfig interface) and hopefully a better performing sample grabber filter implementation to capture still images. Also the ability to turn the camera flash on and off would be a nice feature (IAMCameraControl interface).

  9. 9
    N Says:

    Nice work.
    When video capture?
    Thanks for proyect!

  10. 10
    eric Says:

    Can i just still image without preview?

  11. 11
    admin Says:

    Yep

  12. 12
    Gustavo Says:

    Hi Alex, congratulations for your blog, its very useful.

    Im testing DirectShowNETCF to timed capture images (withou preview - its an automatic process).

    I find that when firing screen saver, its imposible capture images. You know how I can programmatically in C# prevent/disable the screen saver before capturing the images and then back on?

    Thanks.

  13. 13
    Chetan Says:

    I’m confuje for that plz help me

    plz send me that code how to capture image i realy

    want that

    3days i’m trying that thing plz help me my last date is 2mmaro

    regards: chetan

  14. 14
    admin Says:

    what code? you can buy library and will have code

Leave a Reply