smasherprog / screen_capture_lite

cross platform screen/window capturing library
MIT License
638 stars 156 forks source link

How to select a single Monitor? #21

Closed JulianMined closed 7 years ago

JulianMined commented 7 years ago

Hello, how can i select a single Monitor?

smasherprog commented 7 years ago

As part of the setup you have to pass a function here https://github.com/smasherprog/Screen_Capture/blob/master/include/ScreenCapture.h#L141

The library uses a callback to determine which monitors to capture You could do something like this

auto framgrabber = SL::Screen_Capture::CreateScreeCapture([]() {
  //Modify this function to return the monitors you want to capture
  //for example this takes the first monitor and only captures that, but it can be any monitor as long as it is valid
  std::vector<std::shared_ptr<Monitor>> tmp;
  auto allmonitors=SL::Screen_Capture::GetMonitors();
  tmp.push_back(allmonitors[0]);
  return tmp;
  }).onFrameChanged([&](const SL::Screen_Capture::Image& img, const SL::Screen_Capture::Monitor& monitor) {

  }).onNewFrame([&](const SL::Screen_Capture::Image& img, const SL::Screen_Capture::Monitor& monitor) {

  }).onMouseChanged([&](const SL::Screen_Capture::Image* img, int x, int y) {

  }).start_capturing();

framgrabber.setFrameChangeInterval(std::chrono::milliseconds(100));//100 ms
framgrabber.setMouseChangeInterval(std::chrono::milliseconds(100));//100 ms
JulianMined commented 7 years ago

It' working, thank you.

smasherprog commented 7 years ago

Glad to hear.

grz0zrg commented 7 years ago

Hello, it seem that under Linux, all monitors are captured even with the sample code above.

smasherprog commented 7 years ago

You are Correct.. Ill take a look at that now

smasherprog commented 7 years ago

Almost done fixing this

smasherprog commented 7 years ago

This should be fixed for Linux now . . . I also added support for capturing part of the monitor that you wanted. This is supported naively on Linux. I updated the example to show how you can capture just a part of the monitor. https://github.com/smasherprog/screen_capture_lite/blob/master/Example/Screen_Capture_Example.cpp#L35 Care should be taken to make sure you are WITHIN the bounds of the monitor otherwise the library will continually rebuild itself and never capture anything because it thinks the monitors have changed. Capturing just the top left 512x512 squares on two monitors, I was getting over 2k fps so its pretty efficient.

I am now implementing windows/mac variants of this as well.

smasherprog commented 7 years ago

This is in master, but not part of a release yet as there is more work to be done. It appears to work in linux now

smasherprog commented 7 years ago

I am still adding checks to make sure the area is within the monitors so there might be a few bugs, but they will be fixed today

smasherprog commented 7 years ago

This should be fixed now. Added support for capturing part of the monitor as well. . .

grz0zrg commented 7 years ago

Great, i will test this out this week, i hope that partial capture on Mac is possible

smasherprog commented 7 years ago

I didnt implement this for mac just yet.. only windows and linux..

I have to research more for the mac version