TVideoCaptureDevice未在Android上调用SampleBufferReady
我正在开发一个应用程序,它必须在iOS、Android和W32/64上运行,并在RAD Studio XE5上使用Delphi FireMonkey。我正试图进入摄像机以便扫描条形码 我使用USB网络摄像头在W32上运行了示例TVideoCaptureDevice未在Android上调用SampleBufferReady,android,delphi,camera,firemonkey,Android,Delphi,Camera,Firemonkey,我正在开发一个应用程序,它必须在iOS、Android和W32/64上运行,并在RAD Studio XE5上使用Delphi FireMonkey。我正试图进入摄像机以便扫描条形码 我使用USB网络摄像头在W32上运行了示例VideoCaptureHD应用程序,但在Android上,该应用程序只显示背景颜色,没有来自摄像头的图像。我已经在SampleBufferReady方法中添加了一个断点,但它从未被调用 此外,捕获按钮被启用,指示相机设备在某种程度上被识别 //--------------
VideoCaptureHD
应用程序,但在Android上,该应用程序只显示背景颜色,没有来自摄像头的图像。我已经在SampleBufferReady
方法中添加了一个断点,但它从未被调用
此外,捕获按钮被启用,指示相机设备在某种程度上被识别
//---------------------------------------------------------------------------
// This software is Copyright (c) 2012 Embarcadero Technologies, Inc.
// You may only use this software if you are an authorized licensee
// of Delphi, C++Builder or RAD Studio (Embarcadero Products).
// This software is considered a Redistributable as defined under
// the software license agreement that comes with the Embarcadero Products
// and is subject to that software license agreement.
//---------------------------------------------------------------------------
unit CaptureForm;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.Objects, FMX.Media, FMX.StdCtrls,
FMX.Layouts, FMX.ListBox;
type
TForm1 = class(TForm)
Image1: TImage;
CaptureButton: TSpeedButton;
Layout1: TLayout;
SaveDialog1: TSaveDialog;
Ellipse1: TEllipse;
StopButton: TSpeedButton;
procedure FormCreate(Sender: TObject);
procedure CaptureButtonClick(Sender: TObject);
procedure StopButtonClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
VideoCamera: TVideoCaptureDevice;
procedure SampleBufferReady(Sender: TObject; const ATime: TMediaTime);
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.FormCreate(Sender: TObject);
begin
VideoCamera := TCaptureDeviceManager.Current.DefaultVideoCaptureDevice;
if VideoCamera <> nil then
begin
Ellipse1.AnimateFloat('Opacity', 1, 1.0);
VideoCamera.OnSampleBufferReady := SampleBufferReady;
VideoCamera.StartCapture;
end
else
begin
CaptureButton.Enabled := False;
Caption := 'Video capture devices not available.';
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
if VideoCamera <> nil then
VideoCamera.StopCapture;
end;
procedure TForm1.SampleBufferReady(Sender: TObject; const ATime: TMediaTime);
begin
VideoCamera.SampleBufferToBitmap(Image1.Bitmap, True);
end;
procedure TForm1.StopButtonClick(Sender: TObject);
begin
if VideoCamera <> nil then
begin
if VideoCamera.State = TCaptureDeviceState.Capturing then
begin
Ellipse1.AnimateFloat('Opacity', 0, 1.0);
StopButton.Text := 'Capture';
VideoCamera.StopCapture;
end
else
begin
Ellipse1.AnimateFloat('Opacity', 1, 1.0);
StopButton.Text := 'Stop';
VideoCamera.StartCapture
end;
end;
end;
procedure TForm1.CaptureButtonClick(Sender: TObject);
begin
if SaveDialog1.Execute then
Image1.Bitmap.SaveToFile(SaveDialog1.FileName);
end;
end.
//---------------------------------------------------------------------------
//本软件版权所有(c)2012 Embarcadero Technologies,Inc。
//只有在您是授权许可证持有人的情况下,您才能使用本软件
//Delphi、C++Builder或RAD Studio(Embarcadero产品)的制造商。
//本软件被视为可再发行软件,定义见
//Embarcadero产品附带的软件许可协议
//并受该软件许可协议的约束。
//---------------------------------------------------------------------------
单位捕获形式;
界面
使用
System.SysUtils、System.TYPE、System.UITYPE、System.Classes、System.VARIANT、,
FMX.类型,FMX.控件,FMX.窗体,FMX.对话框,FMX.对象,FMX.媒体,FMX.StdCtrls,
FMX.Layouts,FMX.ListBox;
类型
TForm1=类(TForm)
图1:TImage;
CaptureButton:TSpeedButton;
布局1:TLayout;
SaveDialog1:TSaveDialog;
Ellipse1:TEllipse;
停止按钮:TSpeedButton;
过程表单创建(发送方:ToObject);
过程捕获按钮单击(发送方:ToObject);
程序停止按钮单击(发送方:ToObject);
销毁程序表(发送方:TObject);
私有的
{私有声明}
平民的
{公开声明}
摄像机:电视摄像设备;
程序SampleBufferReady(发送方:TObject;常量:tmeditime);
终止
变量
表1:TForm1;
实施
{$R*.fmx}
过程TForm1.FormCreate(发送方:TObject);
开始
摄像机:=TCaptureDeviceManager.Current.DefaultVideoCaptureDevice;
如果摄像机为零,那么
开始
Ellipse1.AnimateFloat('Opacity',1,1.0);
VideoCamera.OnSampleBufferReady:=SampleBufferReady;
摄像机。开始拍摄;
终止
其他的
开始
CaptureButton.Enabled:=False;
标题:='视频捕获设备不可用';
终止
终止
程序TForm1.FormDestroy(发送方:ToObject);
开始
如果摄像机为零,那么
摄像机。停止捕捉;
终止
程序TForm1.SampleBufferReady(发送方:TObject;常量:tmeditime);
开始
摄像机.SampleBufferToBitmap(Image1.Bitmap,True);
终止
程序TForm1.停止按钮单击(发送方:TObject);
开始
如果摄像机为零,那么
开始
如果VideoCamera.State=TCaptureDeviceState.Capturing,则
开始
Ellipse1.AnimateFloat('Opacity',0,1.0);
StopButton.Text:=“捕获”;
摄像机。停止捕捉;
终止
其他的
开始
Ellipse1.AnimateFloat('Opacity',1,1.0);
StopButton.Text:=“停止”;
摄像机
终止
终止
终止
步骤t用于M1.CaptureButtonClick(发送方:ToObject);
开始
如果是SaveDialog1.exe,则执行
Image1.Bitmap.SaveToFile(SaveDialog1.FileName);
终止
终止
我在您的应用程序中找不到bug或错误
您还应该检查Project->Options->UseSemisions->Android->Camera中的是否为真
我做了类似的应用程序,它工作正常(公共变量与您的相同):
procedure TForm1.按钮1点击(发送方:TObject)//单击开始捕获
开始
摄像机。开始拍摄;
终止
程序TForm1.按钮2单击(发送方:TObject)//单击停止捕获
开始
摄像机。停止捕捉;
终止
程序TForm1.按钮3点击(发送方:TObject)//单击即可创建摄影机
开始
摄像机:=TCaptureDeviceManager.Current.DefaultVideoCaptureDevice;
如果摄像机为零,那么
开始
VideoCamera.OnSampleBufferReady:=SampleBufferReady;
终止
其他的
开始
ShowMessage(“视频捕获设备不可用”);
终止
终止
过程TForm1.SampleBufferReady(发送方:TObject;常量:tmeditime);//复制到位图效果完美
开始
摄像机.SampleBufferToBitmap(Image1.Bitmap,True);
终止
procedure TForm1.Button1Click(Sender: TObject); //starts capturing on click
begin
VideoCamera.StartCapture;
end;
procedure TForm1.Button2Click(Sender: TObject); //stops capturing on click
begin
VideoCamera.StopCapture;
end;
procedure TForm1.Button3Click(Sender: TObject); //create camera on click
begin
VideoCamera := TCaptureDeviceManager.Current.DefaultVideoCaptureDevice;
if VideoCamera <> nil then
begin
VideoCamera.OnSampleBufferReady := SampleBufferReady;
end
else
begin
ShowMessage('Video capture devices not available.');
end;
end;
procedure TForm1.SampleBufferReady(Sender: TObject; const ATime: TMediaTime); // copy to bitmap works perfect
begin
VideoCamera.SampleBufferToBitmap(Image1.Bitmap, True);
end;