Lazarus
Programming => Operating Systems => Windows CE => Topic started by: sandeep_c24 on July 19, 2008, 12:43:49 am
-
Hi
Does anyone know how to use the camera to take pictures and use it in an application?
I would like to use KOL-CE and SQLite to store data and images.
Any suggestions?
Regards
Sandeep
-
If C++ Code is helpful: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1811813&SiteID=1
But if you are running something older then WM5 it is very.. complicated
-
Thanks for that. I tried it but for some reason it did not work on my HTC device.
Sandeep
-
Mhhh...maybe you should try and ask Ms directly....and please if you found something post it here...
-
I found this web page http://sondreb.com/blog/post/Windows-Mobile-Photo-Capture.aspx that has a program in C++ (i think), that takes pictures in a period of time. It uses a custom .dll (the mobilecamera.dll) to achieve that.
I tried to port this code to a project of mine, but no luck. this is the code i used:
Declaration of the functions:
Function CaptureStill(filename:string):boolean; stdcall; external 'mobilecamera.dll' name 'CaptureStill';
Function InitializeGraph(p:HWND):boolean; stdcall; external 'mobilecamera.dll' name 'InitializeGraph';
and i am trying to take a shot with this:
var b:boolean;
begin
InitializeGraph(form1.Handle);
sleep(1000);
b:=CaptureStill(home+'image.jpg');
sleep(3000);
if b=true then begin
label1.caption:='ok';
//image1.Picture.LoadFromFile(home+'image.jpg');
end else label1.caption:='not ok';
end;
All i succeed is to take a true response from the capturestill function, but no file is written in the flashcard (or anywhere else).
Any suggestions? Is there any other way to take pictures with my mobile phones camera, periodically?
-
Hello, If you use a Timage, and change the initialiseGraph, for this one:
InitializeGraph(Image1.Handle)
It's only one idea. I didn't test it.
/BlueIcaro
-
hmm... timage has not a handle property, so i used the handle propert of tcanvas, image1.canvas.handle and now every time i try to take a photo the image component fills with black color. Still no file is written to the flash card. Well... it is something... :D
-
Don't mix a TWinControl.Handle (HWND) with a TCanvas.Handle (HDC). They are not the same
The function requires a HWND, so passing a Form1.Handle should be OK. Is there somewhere documented what this handle is supposed to be ?
Anyway, I doubt that the CaptureStill function is translated correctlyFunction CaptureStill(filename:string):boolean; stdcall; external 'mobilecamera.dll' name 'CaptureStill';
c or c++ doesn't know the pascal stringtype, so I assime there originally was somthing with a pchar. Wild guess:Function CaptureStill(filename:pchar):boolean; stdcall; external 'mobilecamera.dll' name 'CaptureStill';
edit:
I downloaded the zip and has a look in MainForm.cs. I've no clue how a C# string is passed to a dll.
-
c or c++ doesn't know the pascal stringtype, so I assime there originally was somthing with a pchar. Wild guess:
I tried... no luck... :(
I also tried a different approach for the camera... i found at the MSDN a function that invokes the camera and i wrote a small API to use it... When i use it, the camera application starts and is ready to record/capture, but when i press "OK" no file is saved again. Sometimes i get an exception error. Another matter with this is that even in the MSDN docs, tells to use the CAMERACAPTURE_MODE_STILL value to capture an image, when the camera starts is only ready for capture video? >:( Why?
Below is the API:
unit camcapi;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Windows;
const
max_path = 256;
type
//http://msdn.microsoft.com/en-us/library/bb431794.aspx
PSHCameraCapture=^TSHCameraCapture;
TSHCameraCapture=packed record
cbSize:dword;
Owner :HWND;
szFile: array[0..MAX_PATH-1] of Char;
pszInitialDir:pchar;
pszDefaultFileName:pchar;
pszTitle:pchar;
StillQuality:byte;
VideoTypes:dword;
nResolutionWidth:dword;
nResolutionHeight:dword;
nVideoTimeLimit:dword;
Mode:byte;
end;
const
External_lib = 'aygshell.dll';
//http://msdn.microsoft.com/en-us/library/bb416617.aspx
CAMERACAPTURE_VIDEOTYPE_ALL = $FFFF;
CAMERACAPTURE_VIDEOTYPE_STANDARD = 1;
CAMERACAPTURE_VIDEOTYPE_MESSAGING = 2;
//http://msdn.microsoft.com/en-us/library/bb416521.aspx
CAMERACAPTURE_MODE_STILL = 0;
CAMERACAPTURE_MODE_VIDEOONLY = 1;
CAMERACAPTURE_MODE_VIDEOWITHAUDIO = 2;
//http://msdn.microsoft.com/en-us/library/bb431719.aspx
CAMERACAPTURE_STILLQUALITY_DEFAULT = 0;
CAMERACAPTURE_STILLQUALITY_LOW = 1;
CAMERACAPTURE_STILLQUALITY_NORMAL = 2;
CAMERACAPTURE_STILLQUALITY_HIGH = 3;
// The method completed successfully.
S_OK = 0;
// The user canceled the Camera Capture dialog box.
S_FALSE =1;
// There is not enough memory to save the image or video.
E_OUTOFMEMORY = $8007000E;
// An invalid argument was specified.
E_INVALIDARG = $80070057;
function CameraCapture(info:tSHCameraCapture):string;
var
DLLLoaded: Boolean = False;
function _CameraCapture(info:PSHCameraCapture): hresult;external External_lib name 'SHCameraCapture';
implementation
var
SaveExit: pointer;
DLLHandle: THandle;
procedure NewExit; far;
begin
ExitProc := SaveExit;
FreeLibrary(DLLHandle)
end {NewExit};
function CameraCapture(info: tSHCameraCapture): string;
var i:integer;
pinfo:pSHCameraCapture;
begin
pinfo:=nil;
pinfo:=@info;
i:=_CameraCapture(pinfo);
case i of
0: result:=pinfo^.szFile;
1: result:='** Error ** False';
E_OUTOFMEMORY:result:='** Error ** Out of Memory';
E_INVALIDARG:result:='** Error ** Invalid Argument';
else result:='** Error **';
end;
end;
procedure LoadDLL;
begin
if DLLLoaded then Exit;
DLLHandle := LoadLibrary(external_lib);
if DLLHandle >= 32 then
begin
DLLLoaded := True;
SaveExit := ExitProc;
ExitProc := @NewExit;
end
else
begin
DLLLoaded := False;
{ Error: aygshell.DLL could not be loaded !! }
end;
end ;
begin
LoadDLL;
end.
and the code to start it is:
var b:string;
tinfo:tSHCameraCapture;
begin
with tinfo do begin
Owner :=0;
// szFile:='\\';
pszInitialDir:=pchar('\Storage Card\');
pszDefaultFileName:=pchar('image.jpg');
pszTitle:=pchar('Camera');
StillQuality:=CAMERACAPTURE_STILLQUALITY_NORMAL;
VideoTypes:=CAMERACAPTURE_VIDEOTYPE_STANDARD;
nResolutionWidth:=640;
nResolutionHeight:=480;
nVideoTimeLimit:=5;
Mode:=CAMERACAPTURE_MODE_STILL;
cbSize:=sizeof(tinfo);
end;
b:=cameracapture(tinfo);
memo1.lines.add(b);
if fileexists(tinfo.szfile) then memo1.lines.add('file ok') else
memo1.lines.add('no file');
memo1.Lines.SaveToFile('\Storage Card\log.txt');
end;
-
Again....
TSHCameraCapture=record
...
szFile:string;
...
end;
WinApi headers never can have members of automated pascal types like string or dynarray. Don't makup headers, translate them exactly. For the simple reason that WinApi has no knowledge of pascal types. It only knows some simple types like integer ot pointer
-
well... i managed to correct the SHCameraCapture record, and now i am able to take a picture with my camera and save the file. The image is saved at the default location (ex: 'My Documents\My Pictures\).
The only problem is that when i take the photo, the szfile should contain the image filename, instead contains nothing?
I modified my previous post with the correct API code...
-
well... i managed to correct the SHCameraCapture record, and now i am able to take a picture with my camera and save the file. The image is saved at the default location (ex: 'My Documents\My Pictures\).
:)
The only problem is that when i take the photo, the szfile should contain the image filename, instead contains nothing?
How do you check if it contains something ?
-
i write the value of it in a label or memo with the strpas function (array to string conversion)... also according to the MSDN this variable should contain the complete path of the file (photo/video) that you capture. Even if i managed, finally, to get the file... it is always saved under the default location (my documents\my pictures) and the szfile variable contains a '\' string only.
-
Hi.. cant you a post you code, im interesant the instant take a photo from my camera.
Tanks.. regards..
-
Hi.. cant you a post you code, im interesant the instant take a photo from my camera.
Well... actually i haven't succeed to take instant photos. I found a .dll file that someone else made and i am trying to port his code to lazarus, but no luck.
-
i write the value of it in a label or memo with the strpas function (array to string conversion)... also according to the MSDN this variable should contain the complete path of the file (photo/video) that you capture. Even if i managed, finally, to get the file... it is always saved under the default location (my documents\my pictures) and the szfile variable contains a '\' string only.
That's what I thought. StrPas only handles Ansi characters, while CE uses WideChars. So StrPas sees a #0 after the first \
Use some WideChar to UTF8 conversion to display it in Lazarus (I don't recall the name of the function)
-
I figure it out... so here it is...
This is a way to get a photo, without invoking the Camera application of the windows mobile phone. To use it, add to your uses the capstill unit and copy the .dll file to your application directory or inside the \windows dir of the WM phone.
You can make a capture with the code below, just add it to a button click or something else.
if InitGraph(form1.handle) then CaptureStill(widestring('\My Documents\image1.jpg'));
The file must not pre-exist or the function will fail.
-
Thank you for the post, I tested in WM6 emulator and it's works, but in my PocketPc Hp rx3715 with WM5 says me that the project is not a valid application :'(
/BLueIcaro
Edit: I copy the .exe file and the .dll file to the storage card
-
To avoid the widestring cast, you can declare CaptureStill like
Function CaptureStill(filename:pwidechar):boolean; stdcall; external 'mobilecamera.dll' name 'CaptureStill';
-
Anyone have a sample app for the above code or simple step by step instructions on how to use.
Cheers
SteveW
-
Okay for anyone else using this I created a new application. with a button with:
if InitGraph(form1.handle) then CaptureStill(widestring('\My Documents\image1.jpg'));
Put the dll & capstill.pas in the same directory.
It worked ......... :D
I now need to develope this and add functionality to it. Some questions.
1. Can I pass parameters to the request IE resolution / flash / brightness etc etc.
2. Is it possible to have a preview of the camera ?
Any info appreciated.
Cheers
SteveW
-
Sorry also added capstill.pas to the uses clause.
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, capstill;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
if InitGraph(form1.handle) then CaptureStill(widestring('\My Documents\image1.jpg'));
end;
initialization
{$I unit1.lrs}
end.
-
I tried adding the capstill.pas to a basic KOL project and I get this error:
unit1.pas(68,26) Error: identifier idents no member "handle"
if InitGraph(form1.handle) then CaptureStill(widestring('\My Documents\image1.jpg'));
Any ideas?
Cheers
SteveW
-
i write the value of it in a label or memo with the strpas function (array to string conversion)... also according to the MSDN this variable should contain the complete path of the file (photo/video) that you capture. Even if i managed, finally, to get the file... it is always saved under the default location (my documents\my pictures) and the szfile variable contains a '\' string only.
Maybe you are using the wrong string type. WinCE usually uses PWideChar and not PChar. You have to check what exactly the API is using and also the encoding and convert property to a utf-8 pascal string to show in a Label.
-
Found sample on previous post.
thanks
Where I can find capstill.pas?
thanks
Sorry also added capstill.pas to the uses clause.
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, capstill;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
if InitGraph(form1.handle) then CaptureStill(widestring('\My Documents\image1.jpg'));
end;
initialization
{$I unit1.lrs}
end.