How access webcam that's running in a separated thread?

175 views Asked by At

I have this class to handle my webcam and want know how can stop the webcam started in a separated thread. Camera.Destroy not is working and the camera keep on.

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Panel1: TPanel;
    Image1: TImage; // To load camera Bitmap from stream
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

type
  TCameraThread = class(TThread)
  protected
    procedure Execute; override;
  end;

var
  Form1: TForm1;

implementation

uses
  Webcam;

{$R *.dfm}

procedure TCameraThread.Execute;
begin
  Camera := TCamera.Create(Form1.Panel1);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  mCamera: TCameraThread;
begin
  mCamera := TCameraThread.Create(False);
  mCamera.Resume;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  if Assigned(Camera) then
    Camera.Destroy;
end;

end.
0

There are 0 answers