在程序中压缩sql server2000的数据库备份文件的代码

如何压缩sqlserver2002的数据库备份文件,像rar相通?二弟有一7m的sqlserver2000数据库备份文件,在前后相继中怎么着压缩啊? 复制代码
代码如下:procedureTForm1.Button2Click(Sender:TObject卡塔尔国; var
SHExecInfo:SHELLEXECUTEINFO; begin
SHExecInfo.cbSize:=sizeof(SHELLEXECUTEINFOState of Qatar;
SHExecInfo.fMask:=SEE_MASK_NOCLOSEPROCESS; SHExecInfo.Wnd:=Handle;
SHExecInfo.lpVerb:=nil; SHExecInfo.lpFile:=’WinRAR.exe’;
SHExecInfo.lpParameters:=’ae:\qwqw.rare:\qwqw’;
SHExecInfo.lpDirectory:=nil; SHExecInfo.nShow:=SW_SHOW;
SHExecInfo.hInstApp:=Handle; ShellExecuteEx(@SHExecInfo);
WaitForSingleObject(SHExecInfo.hProcess,INFINITE);
CloseHandle(SHExecInfo.hProcess);
ShellExecute(application.MainForm.Handle,’open’,’winrar.exe’,PChar(‘ae:\zqzq.rare:\zqzq’),”,SW_showState of Qatar;
ShowMessage(‘压缩完成!’卡塔尔(قطر‎;}那是一段压缩图片的代码,压缩文件原理相近,只需稍做退换就能够。
复制代码 代码如下:var mss:TMemoryStream;
zip:TDeCompressionStream; zip1:TCompressionStream; fs:TFileStream;
fBuf:Array[0..16383]ofByte; flen:Integer; //从数据库中抽出图片
//…写出SQL语句以获得有图片的笔录,此处从略 mss:=TMemoryStream.Create;
fs:=TFileStream.Create(‘filename.jpg’,fmCreateorfmOpenWrite卡塔尔国; try
TBlobField(Que.菲尔德ByName(‘pic’卡塔尔卡塔尔(قطر‎.SaveToStream(mssState of Qatar;
zip:=TDeCompressionStream.Create(fs卡塔尔国; try
flen:=zip.Read(fbuf,SizeOf(fBuf卡塔尔国卡塔尔(قطر‎; whileflen0dobegin
fs.Write(fbuf,flenState of Qatar; flen:=zip.Read(fbuf,SizeOf(fBuf卡塔尔(قطر‎卡塔尔(قطر‎; end; finally
FreeAndNil(zipState of Qatar; end; finally mss.Free; fs.Free; end;
//将文件filename.jpg中的图片保存到数据库
//…写出SQL语句,张开Que,并定位到要保存图片的记录,此处从略
fs:=TFileStream.Create(‘filename.jpg’,fmOpenReadState of Qatar;
mss:=TMemoryStream.Create; try
zip1:=TCompressionStream.Create(clDefault,mss卡塔尔(قطر‎; try
flen:=fs.Read(fbuf,SizeOf(fBuf卡塔尔(قطر‎卡塔尔; whileflen0dobegin
zip1.Write(fbuf,flen卡塔尔; flen:=fs.Read(fbuf,SizeOf(fBuf卡塔尔State of Qatar; end;
//保存到数据库 TBlobField(Que.FieldByName(‘pic’State of QatarState of Qatar.LoadFromStream(mssState of Qatar;
Que.UpdateBatch(卡塔尔; //… finally zip1.Free; end; finally fs.Free;
mss.Free; end;

procedure GetScreen(var Bmp: TBitmap);
var
Dc: HDC;
MyCanvas: TCanvas;
MyRect: TRect;
begin
Dc := GetWindowDC(0);
MyCanvas := TCanvas.Create;
try
MyCanvas.Handle := Dc;
MyRect:=Rect(0,0,Screen.Width, Screen.Height);
//图像为 二十九个人真彩色,也可依据实际需求调动
Bmp.PixelFormat := pf24bit;
Bmp.Width := MyRect.Right;
Bmp.Height := MyRect.Bottom;
//捕捉整个屏幕图像
Bmp.Canvas.CopyRect(MyRect, MyCanvas, MyRect);
finally
MyCanvas.Handle := 0;
MyCanvas.Free;
ReleaseDC(0, Dc);
end;
end;

1、怎么着落到实处在Microsoft Access数据库中的图像存款和储蓄:
那边是利用TStream的子类TMemoryStream向Microsoft
Access数据库中储存图像的。
上边的这段代码是在按了“保存”开关之后所接触的事件管理程序:
procedure TForm1.Button1Click(Sender: TObject);
Var
MyJPEG : TJPEGImage;
MS: TMemoryStream;
Begin
MyJPEG := TJPEGImage.Create;
Try
With MyJPEG do
Begin
Assign(Image.Picture.Graphic);
MS:=TMemoryStream.create;
SaveToStream(MS);
MS.Position := 0;
Table1.Edit;
TBlobField(Table1.FieldbyName(‘Image’)).LoadFromStream(MS);
Table1.Post;
Messagebox(Getactivewindow(卡塔尔(قطر‎, ‘图像保存达成!’, ‘保存’, MB_OK);
End;
Finally
MyJPEG.Free;
End;
End;
在此段代码里TStream的子类TMemoryStream利用内部存款和储蓄器流起到了将BMP格式转变为JPEG格式
的中等桥梁的效应。

procedure CompressBitmap(var CompressedStream: TMemoryStream;const
CompressionLevel: TCompressionLevel);
var
SourceStream: TCompressionStream;
DestStream: TMemoryStream;
Count: Integer;
Begin
//得到图像流的原始尺寸
Count := CompressedStream.Size;
DestStream := TMemoryStream.Create;
SourceStream:=TCompressionStream.Create(CompressionLevel, DestStream);
Try
//SourceStream中保留着原始的图像流
CompressedStream.SaveToStream(SourceStream);
//将原有图像流进行压缩, DestStream中保存着压缩后的图像流
SourceStream.Free;
CompressedStream.Clear;
//写入原始图像的尺寸
CompressedStream.WriteBuffer(Count, SizeOf(Count));
//写入经过压缩的图像流
CompressedStream.CopyFrom(DestStream, 0);
finally
DestStream.Free;
end;
end;

2、怎么着将图像从Microsoft Access数据库中抽出并出示出来:
上面包车型客车这段代码是在按了“查看图像”开关之后所接触的事件管理程序:
procedure TForm1.Button1Click(Sender: TObject);
Var
MyJPEG : TJPEGImage;
MS : TMemoryStream;
Begin
Try
MS := TMemoryStream.Create;
TBlobField(Query1.FieldByName(‘Image’)).SaveToStream(MS);
MS.Position := 0;
MyJPEG := TJPEGImage.Create;
MyJPEG.LoadFromStream(MS);
DBImage1.Picture.Bitmap.Assign(MyJPEG);
//或是Sender.Picture.Assign(MyJPEG);
Finally
MS.Free;
MyJPEG.Free;
End;
End;

procedure UnCompressBitmap(const CompressedStream: TFileStream; var Bmp:
TBitmap);
var
SourceStream: TDecompressionStream;
DestStream: TMemoryStream;
Buffer: PChar;
Count: Integer;
Begin
//从被减去的图像流中读出原本图像的尺寸
CompressedStream.ReadBuffer(Count, SizeOf(Count));
//根据图像尺寸大小为将在读入的原来图像流分配内部存款和储蓄器块
GetMem(Buffer, Count);
DestStream := TMemoryStream.Create;
SourceStream := TDecompressionStream.Create(CompressedStream);
Try
//将被减少的图像流解压缩,然后存入 Buffer内部存款和储蓄器块中
SourceStream.ReadBuffer(Buffer^, Count);
//将原始图像流保存至 DestStream流中
DestStream.WriteBuffer(Buffer^, Count);
DestStream.Position := 0;//重新载入参数流指针
//从 DestStream流中载入原始图像流
Bmp.LoadFromStream(DestStream);
finally
FreeMem(Buffer);
DestStream.Free;
end;
end;

==========================================================================