[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
Filed under: Programming
July 11th, 2009 at 12:11 am
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.
July 11th, 2009 at 12:38 am
Nope i did not try with Framework higher than 2.0 will test it next week
July 14th, 2009 at 8:03 pm
Hello JDS, yes it was bug!
P.S. Already fixed
July 19th, 2009 at 4:42 am
Thanks, Alex.
July 24th, 2009 at 11:37 am
it still throws an exception for me. where is the updated .dll located?
Thank you.
July 24th, 2009 at 11:39 am
irectShowNETCF.Camera.AMCamera.AMResult result = cam_.init();
Can’t find PInvoke DLL ‘DirectShowNETCF.Native.dll’.
Please help
July 28th, 2009 at 10:12 am
you should place DirectShowNETCF.Native.dll to the same folder where exacutable placed
August 9th, 2009 at 1:31 am
Hi Alex,
Is it possible to draw graphics (i.e. a Graphics object) on top of the preview while previewing?
Great little peace of code
Best regards
NJ
August 24th, 2009 at 5:30 pm
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.
August 24th, 2009 at 5:37 pm
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
September 8th, 2009 at 2:53 pm
Hi Alex,
~ Great Job ~
It is possible to draw a rectangle.