主题:[讨论]请问,以下Socket程序有啥问题?
以下程序,提取屏幕没问题,可是抓摄像头的图片就有问题,抓出来的大小是0,请各位大虾帮忙.
function TfrmServer.snapScreen():boolean;
var
bmpscreen: Tbitmap;
jpegscreen: Tjpegimage;
FullscreenCanvas: TCanvas;
dc: HDC;
sourceRect, destRect: TRect;
begin
result:=false;
bmpscreen := Tbitmap.create;
//创建储存Jpeg格式的对象
jpegscreen := Tjpegimage.Create;
if zxpm='show' then begin
//得到屏幕设备
dc := getdc(0);
//创建画布句柄
fullscreencanvas := Tcanvas.Create;
fullscreencanvas.Handle := dc;
//创建存储位图对象
bmpscreen.Width := screen.Width;
bmpscreen.Height := screen.Height;
sourcerect := rect(0, 0, screen.Width, screen.Height);
destrect := rect(0, 0, screen.Width, screen.Height);
//将屏幕图象抓取到bmpScreen位图中
bmpscreen.Canvas.CopyRect(sourcerect, fullscreenCanvas, destrect);
end
else begin
SampleGrabber1.GetBitmap(bmpscreen);\\将摄像头图像转成图片
end;
//将图象压缩成Jpeg格式,保存到JpegStream内存流中。
jpegscreen.Assign(bmpscreen);
jpegscreen.CompressionQuality := 40;
jpegscreen.SaveToStream(jpegStream);
jpegstream.Position := 0;
LeftSize := jpegStream.Size;
//释放创建的对象
if zxpm='show' then begin
FullscreenCanvas.Free;
ReleaseDC(0, DC);
end;
bmpscreen.Free;
jpegscreen.Free;
result:=true;
end;
function TfrmServer.snapScreen():boolean;
var
bmpscreen: Tbitmap;
jpegscreen: Tjpegimage;
FullscreenCanvas: TCanvas;
dc: HDC;
sourceRect, destRect: TRect;
begin
result:=false;
bmpscreen := Tbitmap.create;
//创建储存Jpeg格式的对象
jpegscreen := Tjpegimage.Create;
if zxpm='show' then begin
//得到屏幕设备
dc := getdc(0);
//创建画布句柄
fullscreencanvas := Tcanvas.Create;
fullscreencanvas.Handle := dc;
//创建存储位图对象
bmpscreen.Width := screen.Width;
bmpscreen.Height := screen.Height;
sourcerect := rect(0, 0, screen.Width, screen.Height);
destrect := rect(0, 0, screen.Width, screen.Height);
//将屏幕图象抓取到bmpScreen位图中
bmpscreen.Canvas.CopyRect(sourcerect, fullscreenCanvas, destrect);
end
else begin
SampleGrabber1.GetBitmap(bmpscreen);\\将摄像头图像转成图片
end;
//将图象压缩成Jpeg格式,保存到JpegStream内存流中。
jpegscreen.Assign(bmpscreen);
jpegscreen.CompressionQuality := 40;
jpegscreen.SaveToStream(jpegStream);
jpegstream.Position := 0;
LeftSize := jpegStream.Size;
//释放创建的对象
if zxpm='show' then begin
FullscreenCanvas.Free;
ReleaseDC(0, DC);
end;
bmpscreen.Free;
jpegscreen.Free;
result:=true;
end;