Recent

Author Topic: Using Camera  (Read 25721 times)

sandeep_c24

  • Full Member
  • ***
  • Posts: 114
Using Camera
« 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

L85

  • New Member
  • *
  • Posts: 10
RE: Using Camera
« Reply #1 on: August 01, 2008, 10:34:38 am »
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

sandeep_c24

  • Full Member
  • ***
  • Posts: 114
RE: Using Camera
« Reply #2 on: August 04, 2008, 06:10:30 am »
Thanks for that. I tried it but for some reason it did not work on my HTC device.

Sandeep

L85

  • New Member
  • *
  • Posts: 10
Using Camera
« Reply #3 on: August 08, 2008, 11:09:51 am »
Mhhh...maybe you should try and ask Ms directly....and please if you found something post it here...

xqtr

  • New Member
  • *
  • Posts: 21
Re: Using Camera
« Reply #4 on: August 13, 2009, 12:35:53 pm »
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:
Code: [Select]
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:
Code: [Select]
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?


BlueIcaro

  • Hero Member
  • *****
  • Posts: 576
Re: Using Camera
« Reply #5 on: August 13, 2009, 02:20:50 pm »
Hello, If you use a Timage, and change the initialiseGraph, for this one:
Code: [Select]
InitializeGraph(Image1.Handle)
It's only one idea. I didn't test it.

/BlueIcaro
Remenber, the lazarus wiki is your friend: http://wiki.lazarus.freepascal.org/Main_Page
General questions (several lenguages) http://wiki.lazarus.freepascal.org/

xqtr

  • New Member
  • *
  • Posts: 21
Re: Using Camera
« Reply #6 on: August 13, 2009, 10:30:13 pm »
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

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2496
Re: Using Camera
« Reply #7 on: August 14, 2009, 11:13:57 am »
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 correctly
Code: [Select]
Function 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:
Code: [Select]
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.
« Last Edit: August 14, 2009, 11:23:42 am by Marc »
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

xqtr

  • New Member
  • *
  • Posts: 21
Re: Using Camera
« Reply #8 on: August 14, 2009, 09:30:51 pm »
Quote
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:

Code: [Select]
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:
Code: [Select]
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;
« Last Edit: August 16, 2009, 11:10:48 am by xqtr »

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2496
Re: Using Camera
« Reply #9 on: August 16, 2009, 12:41:57 am »
Again....
Code: [Select]
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
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

xqtr

  • New Member
  • *
  • Posts: 21
Re: Using Camera
« Reply #10 on: August 16, 2009, 11:11:56 am »
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...



Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2496
Re: Using Camera
« Reply #11 on: August 17, 2009, 12:40:26 pm »
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\).
:)
Quote
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 stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

xqtr

  • New Member
  • *
  • Posts: 21
Re: Using Camera
« Reply #12 on: August 17, 2009, 12:48:04 pm »
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.

pcicom

  • New member
  • *
  • Posts: 6
Re: Using Camera
« Reply #13 on: August 17, 2009, 08:00:50 pm »
Hi..   cant you a post you code, im interesant the instant take a photo from my camera.

Tanks.. regards..


 

xqtr

  • New Member
  • *
  • Posts: 21
Re: Using Camera
« Reply #14 on: August 18, 2009, 10:59:45 am »
Quote
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.