我正在做一个程序,使用Delphi XE2和VFrames来拍摄网络摄像头的图片来实现此目的,问题是我已经搞清楚了,在一个图形应用程序中,工作正常,但是当我使用单位在控制台应用程序,它返回我错误说使用控制台应用程序中的VFrame在网络摄像机中使用屏幕截图
第一次机会异常在$ 76B6B727。异常类EAccessViolation消息'模块'console.exe'中地址为004A271B的访问冲突。阅读地址00000260'。流程console.exe(3676)
我单位:
unit Webcam;
interface
uses SysUtils, Windows, Vcl.Imaging.Jpeg, Vcl.Graphics, VSample,
VFrames, Classes;
type
TWebcam = class
private
procedure NewVideoFrameEvent(Sender: TObject; Width, Height: integer;
DataPtr: pointer);
public
constructor Create;
destructor Destroy; override;
procedure capture_webcam(take_name: string);
end;
var
web_image: TVideoImage;
name_screen: string;
implementation
constructor TWebcam.Create;
begin
inherited Create;
end;
destructor TWebcam.Destroy;
begin
inherited Destroy;
end;
Procedure TWebcam.NewVideoFrameEvent(Sender: TObject; Width, Height: integer;
DataPtr: pointer);
var
bitmap: TBitmap;
name: string;
begin
name := name_screen;
if (FileExists(name)) then
begin
DeleteFile(Pchar(name));
end;
bitmap := TBitmap.Create;
bitmap.PixelFormat := pf24bit;
web_image.GetBitmap(bitmap);
bitmap.SaveToFile(name);
bitmap.Free;
web_image.VideoStop;
web_image.Free;
end;
procedure TWebcam.capture_webcam(take_name: string);
var
list_cams: TStringList;
begin
web_image := TVideoImage.Create();
list_cams := TStringList.Create;
web_image.GetListOfDevices(list_cams);
if not(list_cams.count = 0) then
begin
name_screen := take_name;
web_image.VideoStart(list_cams[0]);
end;
list_cams.Free;
web_image.OnNewVideoFrame := NewVideoFrameEvent;
end;
end.
控制台:
program console;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
Webcam;
var
webcamz: TWebcam;
begin
try
webcamz := TWebcam.Create();
webcamz.capture_webcam('test.jpg');
webcamz.Free();
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
我应该怎么办?
使用调试器来遍历代码。哪条线特别提出了例外? –
Just in:web_image.VideoStart(list_cams [0]); –
那么在那个时候什么是'list_cams [0]'? 'web_image'是否有效(而不是无)?我们没有准确的安装位置,所以我们无法逐步检查代码并检查变量以缩小它的范围。你需要做那部分。在该行代码中设置断点并运行到断点。然后检查变量以查看它们的值。 '00000260'地址意味着你很可能访问一个零对象的对象属性,并且你只在该行中有几个对象。哪一个是无效的? –