首页  编辑  

屏幕内容以 JPEG 格式存入内存流中

Tags: /超级猛料/Picture.图形图像编程/抓图/   Date Created:

]、。·ˉˇ¨〃々—~‖…’”〕〉》」』〗】∶!"'),.:;?]` procedure SaveScrToStream(AStream: TMemoryStream);

var

 scrWidth, scrHeight: integer;

 DC: hDC;

 FBitmap: TBitmap;

 FJPEGImage: TJPEGImage;

begin

 DC := GetDC(0);

 FBitmap := TBitmap.Create;

 FJPEGImage := TJPEGImage.Create;

 try

   scrWidth := Screen.Width;

   scrHeight := Screen.Height;

   FBitmap.Width := scrWidth;

   FBitmap.Height := scrHeight;

   BitBlt(FBitmap.Canvas.Handle, 0, 0, scrWidth, scrHeight, DC, 0, 0, SRCCOPY);

   FJPEGImage.Assign(FBitmap);

   FJPEGImage.CompressionQuality := 10;

   FJPEGImage.Compress;

   AStream.Clear;

   FJPEGImage.SaveToStream(AStream);

   AStream.Position := 0;

 finally

   FBitmap.Free;

   FJPEGImage.Free;

   ReleaseDC(0, DC);

 end;

end;

//将内存流中的 JPEG 图像显示出来

procedure DrawJpegStream(AStrem: TMemoryStream; AImage: TImage);

var

 FJPEGImage: TJPEGImage;

begin

 FJPEGImage := TJPEGImage.Create;

 try

   FJPEGImage.LoadFromStream(AStream);

   AImage.Width := FJPEGImage.Width;

   AImage.Height := FJPEGImage.Height;

   AImage.Canvas.Draw(0, 0, FJPEGImage);

 finally

   FJPEGImage.Free;

 end;

end;