编写摄像头的问题 ( 积分: 100 )

  • 主题发起人 主题发起人 sffgw
  • 开始时间 开始时间
S

sffgw

Unregistered / Unconfirmed
GUEST, unregistred user!
我MS的AVICAP32.DLL编了个摄像头程序。请问一下,在AVICAP32.DLL中调那个参数可以设置分辨率的大小。我主要的目的就是保存照片。由于保存出来的照片都是800*600,有1M大小。文件太大,怎么可以保存的照片小一点?

代码如下

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;

type
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
hWndC : THandle;
public
{ Public declarations }
end;

var
Form1: TForm1;
const WM_CAP_START = WM_USER;
const WM_CAP_STOP = WM_CAP_START + 68;
const WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10;
const WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11;
const WM_CAP_SAVEDIB = WM_CAP_START + 25;
const WM_CAP_GRAB_FRAME = WM_CAP_START + 60;
const WM_CAP_SEQUENCE = WM_CAP_START + 62;
const WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START + 20;
const WM_CAP_SEQUENCE_NOFILE =WM_CAP_START+ 63;
const WM_CAP_SET_OVERLAY =WM_CAP_START+ 51;
const WM_CAP_SET_PREVIEW =WM_CAP_START+ 50;
const WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START +6;
const WM_CAP_SET_CALLBACK_ERROR=WM_CAP_START +2;
const WM_CAP_SET_CALLBACK_STATUSA= WM_CAP_START +3;
const WM_CAP_SET_CALLBACK_FRAME= WM_CAP_START +5;
const WM_CAP_SET_SCALE=WM_CAP_START+ 53;
const WM_CAP_SET_PREVIEWRATE=WM_CAP_START+ 52;

function capCreateCaptureWindowA(lpszWindowName : PCHAR; dwStyle : longint; x : integer;
y : integer;nWidth : integer;nHeight : integer;ParentWin : HWND;
nId : integer): HWND;STDCALL EXTERNAL 'AVICAP32.DLL';

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
hWndC := capCreateCaptureWindowA('My Own Capture Window',WS_CHILD or WS_VISIBLE ,Panel1.Left,Panel1.Top,Panel1.Width,Panel1.Height,Form1.Handle,0);

hWndC := capCreateCaptureWindowA('My Own Capture Window',WS_CHILD or WS_VISIBLE ,Panel1.Left,Panel1.Top,Panel1.Width,Panel1.Height,Form1.Handle,0);
if hWndC <> 0 then
begin
SendMessage(hWndC, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0);
SendMessage(hWndC, WM_CAP_SET_CALLBACK_ERROR, 0, 0);
SendMessage(hWndC, WM_CAP_SET_CALLBACK_STATUSA, 0, 0);
SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0);
SendMessage(hWndC, WM_CAP_SET_SCALE, 1, 0);
SendMessage(hWndC, WM_CAP_SET_PREVIEWRATE, 66, 0);
SendMessage(hWndC, WM_CAP_SET_OVERLAY, 1, 0);
SendMessage(hWndC, WM_CAP_SET_PREVIEW, 1, 0);
end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
if hWndC <> 0 then begin
SendMessage(hWndC,WM_CAP_SAVEDIB,0,longint(pchar('c://test.bmp')));
end;
end;

end.
 
在内存中是BMP,在实际存储时另存为JPG
 
我试过了,改成jpg还是1M多
 
这个是我几年前写的从摄像头保存图片的代码,写得很差,也许可参考一下

var
bmp:Tbitmap;
JPG:TJpegImage;
begin
if not SaveDialog2.Execute then exit;
bmp:=Tbitmap.Create;
JPG:=TJPEGImage.Create;
bmp.Width:=image.Width;
bmp.Height:=image.Height;
bmp.Canvas.CopyRect(rect(0,0,image.Width,image.Height),image.Canvas,rect(0,0,bmp.Width,bmp.Height));
jpg.CompressionQuality:=value1;//通过设定此值确定JPG文件大小,数值越小,精度越差
JPG.Assign(BMP);

JPG.SaveToFile(SaveDialog2.FileName);

bmp.free;
JPG.Free;
 
转存为JPG的时候,Myjpg.CompressionQuality这个参数决定了转为JPG的精度与大小.


Myjpg:=Tjpegimage.create;
Myjpg.Assign(image1.Picture.Bitmap); //将BMP图象转成JPG格式,便于在互联网上传输
Myjpg.CompressionQuality := 100; //JPG文件压缩百分比设置,数字越大图像越清晰,但数据也越大
Myjpg.Compress; //将JPG图象写入流中
image1.Picture.Graphic:=myjpg;
Myjpg.free;
 
多人接受答案了。
 
后退
顶部