Programming Using mobile phone cameras
Programming Using mobile phone cameras
I had very little information on the Internet and had to explore it for a while. Shared.
References:
Http://msdn.microsoft.com/zh-cn/library/aa454909.aspx for using pictures, videos, and cameras in Windows Mobile 5.0
1. Windows mobile5 or 6
A) use the cameracapturedialog object in dotnetcf framework.
There are many online examples. In practice, I found that it only calls the camera program in the Windows Mobile System.
You can record a video or capture an image at a certain time point. What is returned is a file.
If you want advanced control, it is very difficult. For example, you can analyze the image content in real time when displaying dynamic images.
B) C # Call DirectShow to access camera
You can implement advanced control (Add filter ...)
Before that, I thought about calling DirectShow with C # and found that it was extremely difficult.
DirectShow is actually a <mobile phone directory> \ windows \ quartz. dll, which is not a C # library. If the conversion path is a c‑core library, I can't do it any more. 1no tool (tlbimp.exe can only convert quartz. dll in pcwindows, but this tool does not work for WM system DLL). 2 it is unclear how it works.
I want to use [comvisible (true), comimport,
GUID ("56a86891-0ad4-11ce-b03a-0020af0ba770 "),
Interfacetype (cominterfacetype. interfaceisiunknown)]
Such a declaration of importing com found that there are too many contents to be imported. In fact, I did this. It took a lot of time and failed. It is better to learn C ++ at these times.
C) C ++ calls DirectShow to access camera
After learning C ++, we found an excellent example: after installing the Windows Mobile 5.0 Pocket pc sdk. In
C: \ Program Files \ Windows CE tools \ wce500 \ Windows Mobile 5.0 Pocket pc sdk \ samples \ CPP \ Win32 \ cameracapture
After reading this, I wrote the simplest program, which perfectly demonstrated the mobile phone access to the camera:
Void ctestcpp1dlg: onbnclickedbutton1 ()
{
Coinitialize (null );
// Graphbuilder and capturegraphbuilder
Ccomptr <igraphbuilder> pgraphbuilder;
Ccomptr <icapturegraphbuilder2> pcapturegraphbuilder;
Pcapturegraphbuilder. cocreateinstance (clsid_capturegraphbuilder );
Pgraphbuilder. cocreateinstance (clsid_filtergraph );
Pcapturegraphbuilder-> setfiltergraph (pgraphbuilder );
// Findfirstdevice
Devmgr_device_information di;
Guid guidcamera = {0xcb998a05, 0x122c, 0x4166, 0x84, 0x6a, 0x93, 0x3e, 0x4d, 0x7e, 0x3c, 0x86 };
Di. dwsize = sizeof (DI );
Handle handle = findfirstdevice (devicesearchbyguid, & guidcamera, & di );
Findclose (handle );
// Videocapturefilter
Ccomptr <ibasefilter> pvideocapturefilter;
Ccomptr <ipersistpropertybag> ppropertybag;
Pvideocapturefilter. cocreateinstance (clsid_videocapture );
Pvideocapturefilter. QueryInterface (& ppropertybag );
Ccomvariant varcamname;
Varcamname = Di. szlegacyname;
Cpropertybag propbag;
Propbag. Write (L "vcapname", & varcamname );
Ppropertybag-> load (& propbag, null );
Ppropertybag. Release ();
Pgraphbuilder-> addfilter (pvideocapturefilter, l "video capture source ");
// Renderstream and controlstream
Pcapturegraphbuilder-> renderstream (& pin_category_preview, & mediatype_video, pvideocapturefilter, null, null );
Pcapturegraphbuilder-> controlstream (& pin_category_capture, & mediatype_video, pvideocapturefilter, 0, 0, 0 );
// Videowindow, set the Real-Time captured image as its own form. You can also set it to a subwindow on the form.
Ivideowindow * pvideowindow;
Pgraphbuilder-> QueryInterface (iid_ivideowindow, (void **) & pvideowindow );
Pvideowindow-> put_owner (oahwnd) This-> m_hwnd );
Pvideowindow-> put_windowstyle (ws_child | ws_clipsiblings );
Rect;
Getclientrect (& rect );
Pvideowindow-> setwindowposition (0, 0, rect. Right, rect. Bottom );
// Mediacontrol
Ccomptr <imediacontrol> pmediacontrol;
Pgraphbuilder. QueryInterface (& pmediacontrol );
Pmediacontrol-> Run ();
}
2. J2EE
I have made some explorations in the mobile Java environment.
Mobile phones generally use mmapi to access cameras
1) install jdk1.5, install wtk2.5, and install eclipse.
2) Configure wtk2.5 & eclipse
-----------------------------
Catchscreen. Java
-----------------------------
Import javax. microedition. lcdui .*;
Import javax. microedition. Media. player;
Import javax. microedition. Media. Control. videocontrol;
Import javax. microedition. Media. Manager;
Import javax. microedition. Media .*;
Public class catchscreen extends canvas {
Player P;
Videocontrol VC;
Public static int bytes = 0;
Public catchscreen (){
This. setfullscreenmode (true );
Try {
P = manager. createplayer ("Capture: // video ");
P. Realize ();
VC = (videocontrol) p. getcontrol ("videocontrol ");
If (VC! = NULL ){
VC. initdisplaymode (videocontrol. use_direct_video, this );
VC. setdisplaysize (128,160 );
}
VC. setvisible (true );
P. Start ();
} Catch (exception e ){}
}
Public void keypressed (INT key)
{
Httpthread thread = new httpthread ();
Thread. setdata (VC );
Thread. Start ();
}
Protected void paint (Graphics g ){
G. setcolor (125,125,125 );
G. fillrect (0, 0, getwidth (), getheight ());
G. setcolor (0, 0, 0 );
G. drawline (, 10 );
}
}
-----------------------------
Test1.java
-----------------------------
Import javax. microedition. MIDlet. MIDlet;
Import javax. microedition. MIDlet. midletstatechangeexception;
Import javax. microedition. lcdui .*;
Public class test1 extends MIDlet {
Private display;
Public test1 (){
Display = display. getdisplay (this );
}
Protected void destroyapp (Boolean arg0) throws midletstatechangeexception {
}
Protected void pauseapp (){
}
Protected void Startapp () throws midletstatechangeexception {
Catchscreen = new catchscreen ();
Display. setcurrent (catchscreen );
}
}
Final effect:
In the PC simulator, it seems that capturing images is working. (because there is no camera in the PC simulator, the sun simulator plays a video with imagination :))
Actually, in the WM system (jeodek Java simulator), I captured the image and got it. It may be because the jeodek Java simulator does not support mmapi...
Sony Ericsson's machine cannot show captured images either.
It seems that the gap between Java and Windows Mobile is not small.