[Windows Mobile]Draw Text on preview or SampleGrabber and DirectShow.NETCF

If you ever used DirectShow under windows then you know that if you want draw text on preview you can use VMRRenderer, but windows mobile dont provide any way to draw text on preview :(

I see there only 1 way to solve it - Draw text directly on stream, so we need SampleGrabber to got access to raw stream, also we need to create our own font (thats the main problem). i made small demo that allows draw text on preview.

So IGetFrame was modified:

[ComVisible(true), ComImport,
Guid("2B21644A-D405-4E27-A51C-A4812bE0CE4C"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IGetFrame
{
[PreserveSig]
int getFrame(IntPtr pBuff);

[PreserveSig]
int getSize([Out] out long size);

[PreserveSig]
int getFrameParams(
[Out] out int width,
[Out] out int height,
[Out] out RawFrameFormat format);

[PreserveSig]
int drawText(
[In] IntPtr ptr,
[In] int height,
[In] int width);

[PreserveSig]
int stopDraw();
}

As you can see we got new method: drawText([In] IntPtr ptr, [In] int height, [In] int width);
where ptr - is our text in special format…
how to conver text to IntPtr?
there added extra class: CABC, here is example how to draw text:

CABC abc = new CABC("abcd dabc cdab bcda");
frmGrabber.drawText(abc.getText(), abc.Height, abc.Width);
abc.Dispose();
abc = null;

Also you can check AMCamera example from DirectShowNETCF

11 Responses to “[Windows Mobile]Draw Text on preview or SampleGrabber and DirectShow.NETCF”

Pages: « 2 [1] Show All

  1. 10
    admin Says:

    if you want to overlay image or got callback that returns preview bitmap you have to implement your own samplegrabber or you could wail that one day i will got free time and motivation and free time to do that, but seems it wont be in near future

  2. 9
    Frank Says:

    I also would like to overlay an image on the camera preview. Best would be a semi-transparent image or perhaps a callback function that receives the preview bitmap before it is displayed. That function than could do some painting on the Bitmap like using AlphaBlend.

  3. 8
    NJ Says:

    Hi Alex,
    Great little peace of code :) Is it possible to draw graphics (i.e. a Graphics object) on top of the preview while previewing?

    Best regards
    NJ

  4. 7
    admin Says:

    you should place DirectShowNETCF.Native.dll to the same folder where exacutable placed

  5. 6
    alex Says:

    irectShowNETCF.Camera.AMCamera.AMResult result = cam_.init();

    Can’t find PInvoke DLL ‘DirectShowNETCF.Native.dll’.

    Please help

  6. 5
    alex Says:

    it still throws an exception for me. where is the updated .dll located?

    Thank you.

  7. 4
    JDS Says:

    Thanks, Alex.

  8. 3
    admin Says:

    Hello JDS, yes it was bug!
    P.S. Already fixed

  9. 2
    admin Says:

    Nope i did not try with Framework higher than 2.0 will test it next week

  10. 1
    JDS Says:

    Alex,

    Excellent work. Have you ever tried the AMCamera sample w/CompactFramework v3.5? On my machines (including my hones), the AMCamera.init() method throws a generic exception: “NotSupportedException was unhandled” on this line in the Init_Click event:

    DirectShowNETCF.Camera.AMCamera.AMResult result = cam_.init();

    Any insights? The app works fine if I target the 2.0 CF.

Pages: « 2 [1] Show All

Leave a Reply