Page 1 of 1

How to make SnapShot

Posted: Tue Aug 25, 2020 4:33 am
by ForestListener
Hello.

Is there way to get snapshot when application form with Chromium is not visible?

I've tried built in TakeSnapshot, but it works only when Chromium is on screen.

I need it to get Captha images, because built in downloadimage downloads a new captcha (but i need to use current, opened in Webbrowser captcha image).

Thank you!

Re: How to make SnapShot

Posted: Tue Aug 25, 2020 7:52 am
by salvadordf
Try the "Take screenshot" menu option in the MiniBrowser demo.
https://github.com/salvadordf/CEF4Delph ... .pas#L1111

Re: How to make SnapShot

Posted: Tue Aug 25, 2020 10:16 am
by Student
I think, in this case, it is better to use the event GetResourceResponseFilter, to save a captcha while loading on the fly.
Learn the demo ResponseFilterBrowser, It shows how to save resources in TMemoryStream, and there you can do whatever you want with them.

Re: How to make SnapShot

Posted: Tue Aug 25, 2020 11:08 am
by ForestListener
Thank you!

Re: How to make SnapShot

Posted: Sun Oct 11, 2020 10:50 am
by w1ld32
Student wrote: Tue Aug 25, 2020 10:16 am I think, in this case, it is better to use the event GetResourceResponseFilter, to save a captcha while loading on the fly.
Learn the demo ResponseFilterBrowser, It shows how to save resources in TMemoryStream, and there you can do whatever you want with them.
Sorry, I can't figure out this example, if it's not difficult, show the code how to save logo.png which is in the example without replacing it?

Re: How to make SnapShot

Posted: Sun Oct 11, 2020 12:13 pm
by salvadordf
w1ld32 wrote: Sun Oct 11, 2020 10:50 am
Student wrote: Tue Aug 25, 2020 10:16 am I think, in this case, it is better to use the event GetResourceResponseFilter, to save a captcha while loading on the fly.
Learn the demo ResponseFilterBrowser, It shows how to save resources in TMemoryStream, and there you can do whatever you want with them.
Sorry, I can't figure out this example, if it's not difficult, show the code how to save logo.png which is in the example without replacing it?
All the code is in the ResponseFilterBrowser demo but it's not simple.
If you know the URL of the image consider using TChromium.DownloadImage instead.

Re: How to make SnapShot

Posted: Sun Oct 11, 2020 4:08 pm
by w1ld32
salvadordf wrote: Sun Oct 11, 2020 12:13 pm
w1ld32 wrote: Sun Oct 11, 2020 10:50 am
Student wrote: Tue Aug 25, 2020 10:16 am I think, in this case, it is better to use the event GetResourceResponseFilter, to save a captcha while loading on the fly.
Learn the demo ResponseFilterBrowser, It shows how to save resources in TMemoryStream, and there you can do whatever you want with them.
Sorry, I can't figure out this example, if it's not difficult, show the code how to save logo.png which is in the example without replacing it?
All the code is in the ResponseFilterBrowser demo but it's not simple.
If you know the URL of the image consider using TChromium.DownloadImage instead.
The picture changes every time ((
https://instagram777.ru/captcha2.php

Re: How to make SnapShot

Posted: Tue Oct 13, 2020 9:20 am
by w1ld32
I got out of the situation like this: after loading the page, I find the coordinates of the captcha, take a screenshot and cut out the captcha using these coordinates.

Re: How to make SnapShot

Posted: Tue Oct 13, 2020 9:42 am
by Student
w1ld32 wrote: Tue Oct 13, 2020 9:20 am I got out of the situation like this: after loading the page, I find the coordinates of the captcha, take a screenshot and cut out the captcha using these coordinates.
You need to make changes to the ReplaceLogo procedure, and then in FStream your resource will be located. I can't guarantee that my code is written correctly,
some types of resources may be of unknown size, and I have additional checks in the code.

Code: Select all

  FStreamCS.Acquire;

  if (data_in = nil) then
  begin
    data_in_read := 0;
    data_out_written := 0;
    if FRscCompleted and ((FRscSize = -1) or (FRscSize = FStream.size)) then
    begin
      aResult := RESPONSE_FILTER_DONE;
      PostMessage(handle, STREAM_COPY_COMPLETE, 0, 0);
    end else aResult := RESPONSE_FILTER_NEED_MORE_DATA;
  end
  else
  begin
    aResult := RESPONSE_FILTER_DONE;

    if (data_out <> nil) then
    begin
      data_out_written := min(data_in_size, data_out_size);

      if (data_out_written > 0) then
        Move(data_in^, data_out^, data_out_written);
    end;

    if (data_in_size > 0) then
      data_in_read := FStream.Write(data_in^, data_in_size);

    if not(FRscCompleted) and (FRscSize <> -1) and (FRscSize = FStream.size)
    then
     FRscCompleted := PostMessage(handle, STREAM_COPY_COMPLETE, 0, 0)
    else if data_out_written = 65536 then
      aResult := RESPONSE_FILTER_NEED_MORE_DATA
    else
     FRscCompleted := PostMessage(handle, STREAM_COPY_COMPLETE, 0, 0);
  end;

  FStreamCS.Release;

Re: How to make SnapShot

Posted: Tue Oct 13, 2020 11:32 am
by w1ld32
Student wrote: Tue Oct 13, 2020 9:42 am
w1ld32 wrote: Tue Oct 13, 2020 9:20 am I got out of the situation like this: after loading the page, I find the coordinates of the captcha, take a screenshot and cut out the captcha using these coordinates.
You need to make changes to the ReplaceLogo procedure, and then in FStream your resource will be located. I can't guarantee that my code is written correctly,
some types of resources may be of unknown size, and I have additional checks in the code.

Code: Select all

  FStreamCS.Acquire;

  if (data_in = nil) then
  begin
    data_in_read := 0;
    data_out_written := 0;
    if FRscCompleted and ((FRscSize = -1) or (FRscSize = FStream.size)) then
    begin
      aResult := RESPONSE_FILTER_DONE;
      PostMessage(handle, STREAM_COPY_COMPLETE, 0, 0);
    end else aResult := RESPONSE_FILTER_NEED_MORE_DATA;
  end
  else
  begin
    aResult := RESPONSE_FILTER_DONE;

    if (data_out <> nil) then
    begin
      data_out_written := min(data_in_size, data_out_size);

      if (data_out_written > 0) then
        Move(data_in^, data_out^, data_out_written);
    end;

    if (data_in_size > 0) then
      data_in_read := FStream.Write(data_in^, data_in_size);

    if not(FRscCompleted) and (FRscSize <> -1) and (FRscSize = FStream.size)
    then
     FRscCompleted := PostMessage(handle, STREAM_COPY_COMPLETE, 0, 0)
    else if data_out_written = 65536 then
      aResult := RESPONSE_FILTER_NEED_MORE_DATA
    else
     FRscCompleted := PostMessage(handle, STREAM_COPY_COMPLETE, 0, 0);
  end;

  FStreamCS.Release;
Thank You. I Try it.