ImageEnView 从屏幕截图并转换成8Bit

2020-09-11

Stream := TMemoryStream.Create;

ImageEnView1.IO.CaptureFromScreen(iecsScreen, crNone);

ImageEnView1.IO.IEBitmap.PixelFormat := ie8g;

ImageEnView1.IO.Params.BitsPerSample := 8;

ImageEnView1.IO.Params.SamplesPerPixel := 1;

ImageEnView1.IO.SaveToStreamBmp(Stream);

Stream.Position:= 0;

image1.Picture.LoadFromStream(Stream);

Stream.Free;



9.1.2版本之后,转换可以用: IEGlobalSettings().AutoSetBitDepth := True; 


Examples

// 截图保存到文件 'screen.png'
ImageEnView1.IO.CaptureFromScreen(iecsScreen, -1);
ImageEnView1.IO.SaveToFile('D:\screen.png');

// 截图指定窗体, "Untitled - Notepad"
NotepadHandle := FindWindow(nil, 'Untitled - Notepad');
if NotepadHandle <> 0 then
  ImageEnView1.IO.CaptureFromScreen( iecsSpecifiedWindow, crDefault, NotepadHandle );

//  截图多显示器
for i := 0 to Screen.MonitorCount - 1 do
begin
  ImageEnView1.IO.CaptureFromScreen( iecsSpecifiedMonitor, -1, i );
  ImageEnView1.IO.SaveToFile( format( 'D:\Screen_%d.jpeg', [ i ]));
end;

// 截图主显示器
var
  bmp: TIEBitmap;
  IO: TImageEnIO;
begin
  bmp := TIEBitmap.Create;
  IO := TImageEnIO.CreateFromBitmap( bmp );
  try
    IO.CaptureFromScreen( iecsPrimary );
    ... do something with bmp ...
  finally
    IO.Free;
    bmp.Free;
  end;
end;



阅读147