做法:
1、抓动态视频保存为BMP(临时文件)
2、显示BMP
3、根据鼠标位置和目标大小画一个矩形框预览目标图形(所谓的橡皮筋线),此步也可省略
4、保存时从预览复制CopyRect部分图形,然后保存
下面代码是从我的程序中摘录的,供你参考
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
MyRect, MyOther: TRect;
begin
MyRect := Rect(x,y,x+image2.Width ,y+image2.Height);
MyOther:=Rect(0,0,image2.Width ,image2.Height);
image2.Picture:=nil;
image2.Canvas.CopyRect(MyOther,image1.Picture.Bitmap.Canvas,MyRect);
end;
procedure TForm1.Button3Click(Sender: TObject);
var
JPEGImage: TJPEGImage;
begin
//直接保存会出现错误:
//'project raised exception class EJPEG with
// message 'JPEG error #53'. Process stopped.'
//分析应为保存的jpg文件格式有问题,无法预览
//官方说法是: 53 cstrJERR_OUT_OF_MEMORY
// 'Insufficient memory (case %d)'
if SavePictureDialog1.InitialDir='' then
SavePictureDialog1.InitialDir:=ExtractFilePath(OpenPictureDialog1.FileName);
if trim(LabeledEdit1.Text)<>'' then
SavePictureDialog1.FileName:=trim(LabeledEdit1.Text)+'.jpg';
if SavePictureDialog1.execute then
begin
JPEGImage:=TJPEGImage.Create;
JPEGImage.Assign(image2.Picture.Graphic);
JPEGImage.SaveToFile(ExtractFilePath(SavePictureDialog1.Filename)+trim(LabeledEdit1.Text)+'.jpg');
end;
end;