D
donexie
Unregistered / Unconfirmed
GUEST, unregistred user!
用SampleGrabber抓下来的图,居然是空的,打开什么都没有,可以录像下来~!
procedure TMainForm.StartButtonClick(Sender: TObject);
var
multiplexer: IBaseFilter;
Writer: IFileSinkFilter;
PinList: TPinList;
i: integer;
begin
ASFWriter.FileName:= OutPutFileName.Caption;
// Activate the filter graph, at this stage the source filters are added to the graph
CaptureGraph.Active := true;
// configure output Audio media type + source
if AudioSourceFilter.FilterGraph <> nil then
begin
PinList := TPinList.Create(AudioSourceFilter as IBaseFilter);
i := 0;
while i < PinList.Countdo
if PinList.PinInfo.dir = PINDIR_OUTPUT then
begin
if AudioFormats.ItemIndex <> -1 then
with (PinList.Items as IAMStreamConfig)do
SetFormat(AudioMediaTypes.Items[AudioFormats.ItemIndex].AMMediaType^);
PinList.Delete(i);
end else
inc(i);
if InputLines.ItemIndex <> -1 then
with (PinList.Items[InputLines.ItemIndex] as IAMAudioInputMixer)do
put_Enable(true);
PinList.Free;
end;
// configure output Video media type
if VideoSourceFilter.FilterGraph <> nil then
begin
PinList := TPinList.Create(VideoSourceFilter as IBaseFilter);
if VideoFormats.ItemIndex <> -1 then
with (PinList.First as IAMStreamConfig)do
SetFormat(VideoMediaTypes.Items[VideoFormats.ItemIndex].AMMediaType^);
PinList.Free;
end;
// now render streams
with CaptureGraph as IcaptureGraphBuilder2do
begin
CheckDSError(RenderStream(@PIN_CATEGORY_PREVIEW, nil, VideoSourceFilter as IBaseFilter, nil, VideoWindow as IBaseFilter));
CheckDSError(RenderStream(@PIN_CATEGORY_CAPTURE, nil, VideoSourceFilter as IBaseFilter, nil, ASFWriter as IBaseFilter));
CheckDSError(RenderStream(nil, nil, AudioSourceFilter as IBaseFilter, nil, ASFWriter as IBaseFilter));
end;
CaptureGraph.Play;
Button1Click(Sender);//抓图~!
StopButton.Enabled := true;
StartButton.Enabled := false;
AudioFormats.Enabled := false;
AudioCapFilters.Enabled := false;
VideoFormats.Enabled := false;
VideoCapFilters.Enabled := false;
InputLines.Enabled := false;
Timer.Enabled := true;
end;
procedure TMainForm.Button1Click(Sender: TObject);
var
ABitmap: TBitmap;
begin
ABitmap := TBitmap.Create;
try
SampleGrabber1.GetBitmap(ABitmap);
ABitmap.SaveToFile('c:/111.bmp');
finally
ABitmap.Free;
end;
end;
procedure TMainForm.StartButtonClick(Sender: TObject);
var
multiplexer: IBaseFilter;
Writer: IFileSinkFilter;
PinList: TPinList;
i: integer;
begin
ASFWriter.FileName:= OutPutFileName.Caption;
// Activate the filter graph, at this stage the source filters are added to the graph
CaptureGraph.Active := true;
// configure output Audio media type + source
if AudioSourceFilter.FilterGraph <> nil then
begin
PinList := TPinList.Create(AudioSourceFilter as IBaseFilter);
i := 0;
while i < PinList.Countdo
if PinList.PinInfo.dir = PINDIR_OUTPUT then
begin
if AudioFormats.ItemIndex <> -1 then
with (PinList.Items as IAMStreamConfig)do
SetFormat(AudioMediaTypes.Items[AudioFormats.ItemIndex].AMMediaType^);
PinList.Delete(i);
end else
inc(i);
if InputLines.ItemIndex <> -1 then
with (PinList.Items[InputLines.ItemIndex] as IAMAudioInputMixer)do
put_Enable(true);
PinList.Free;
end;
// configure output Video media type
if VideoSourceFilter.FilterGraph <> nil then
begin
PinList := TPinList.Create(VideoSourceFilter as IBaseFilter);
if VideoFormats.ItemIndex <> -1 then
with (PinList.First as IAMStreamConfig)do
SetFormat(VideoMediaTypes.Items[VideoFormats.ItemIndex].AMMediaType^);
PinList.Free;
end;
// now render streams
with CaptureGraph as IcaptureGraphBuilder2do
begin
CheckDSError(RenderStream(@PIN_CATEGORY_PREVIEW, nil, VideoSourceFilter as IBaseFilter, nil, VideoWindow as IBaseFilter));
CheckDSError(RenderStream(@PIN_CATEGORY_CAPTURE, nil, VideoSourceFilter as IBaseFilter, nil, ASFWriter as IBaseFilter));
CheckDSError(RenderStream(nil, nil, AudioSourceFilter as IBaseFilter, nil, ASFWriter as IBaseFilter));
end;
CaptureGraph.Play;
Button1Click(Sender);//抓图~!
StopButton.Enabled := true;
StartButton.Enabled := false;
AudioFormats.Enabled := false;
AudioCapFilters.Enabled := false;
VideoFormats.Enabled := false;
VideoCapFilters.Enabled := false;
InputLines.Enabled := false;
Timer.Enabled := true;
end;
procedure TMainForm.Button1Click(Sender: TObject);
var
ABitmap: TBitmap;
begin
ABitmap := TBitmap.Create;
try
SampleGrabber1.GetBitmap(ABitmap);
ABitmap.SaveToFile('c:/111.bmp');
finally
ABitmap.Free;
end;
end;