Change resolution of Webcam video using Delphi pr

2020-07-27 04:50发布

问题:

How do I change the size of the webcam from (640x360) as default in VFrames into a (160x120) as the new default.

I'm using this component found on this page.

回答1:

There is a predefined method in VFrames

var
  cam:TVideoImage;
  camlist:TStringList;
  reslist:TStringList;
  vp:TVideoProperty;
begin

   camlist := TStringList.Create ;
   reslist :=TStringList.Create;

   cam := TVideoImage.Create;
   cam.GetListOfDevices(camlist);

   cam.SetDisplayCanvas(PaintBox1.Canvas);

   cam.VideoStart(camlist.Strings[0])    ;

   // important 

   cam.GetListOfSupportedVideoSizes(reslist);
   ListBox1.Items := reslist;
   cam.SetResolutionByIndex(0);

   //specify your resolution by index using listbox index
   //this will not only lists resolutions but also other features available , so be careful when selecting the index
end;

make sure that GetListOfSupportedVideoSizes and SetResolutionByIndex are executed after the video has started to play



回答2:

in this answer i am using bitmap image.

this will be slightly slower than the previous (but hard to notice)

We are going to get the image on every timer tick (eg interval = 100), assign it to our image box then going to modify our size , no matter what is the default resolution is it will get the default size image(eg: 640 * 480) and in the image box we are going to change the size.

uses
  ....
  VFrames;

var
 ....
  cam:TVideoImage;

implementation

 procedure TForm6.FormCreate(Sender: TObject);
 begin
  cam := TVideoImage.Create;

  image1.stretch := true ;
  image1.height := 120 ;
  image1.width := 160 ;

end;

 procedure TForm6.Timer1Timer(Sender: TObject);
 begin
   cam.GetBitmap(Image1.Picture.Bitmap);
 end;

 procedure TForm6.Button1Click(Sender: TObject);
 var
   camlist:TStringList;
 begin

   camlist := TStringList.Create ;

   cam := TVideoImage.Create;
   cam.GetListOfDevices(camlist);

   cam.VideoStart(camlist.Strings[0])    ;

end;


标签: delphi webcam