seafight17 Posted December 1, 2012 Share Posted December 1, 2012 hallo I want to save the scrennshot of the screen (print screen) but not just one time in the sript but many.. it make one scrennshoot(bmp in the folder ) but then it replace it with the new..i want to save all bmp then the " if " is true so after to find them > procedure snapshoot; [scar]begin if ..... then begin /// some actions SaveScreenshot(ScreenPath + 'sunk.bmp'); //snappshoot end; end;[/scar] Quote Link to comment Share on other sites More sharing options...
Janilabo Posted December 1, 2012 Share Posted December 1, 2012 You could do something like this: procedure SaveScreenshot2(Path: string); var ID: Integer; begin if not EndsWith('.bmp', Lowercase(Path)) then Path := (Path + '.bmp'); if FileExists(Path) then begin Delete(Path, (Length(Path) - 3), 4); while FileExists(Path + '(' + IntToStr(ID) + ').bmp') do Inc(ID); SaveScreenshot(Path + '(' + IntToStr(ID) + ').bmp'); end else SaveScreenshot(Path); end; begin SaveScreenshot2(ScreenPath + 'sunk.bmp'); SaveScreenshot2(ScreenPath + 'sunk'); // Just to show that both ways work, without/with ".bmp" end. If you want to keep that a little faster (without scanning files each and everytime again and again, then I recommend you have GLOBAL variable for ID. Like this: var ID: Integer; procedure SaveScreenshot2(Path: string); begin if not EndsWith('.bmp', Lowercase(Path)) then Path := (Path + '.bmp'); if FileExists(Path) then begin Delete(Path, (Length(Path) - 3), 4); while FileExists(Path + '(' + IntToStr(ID) + ').bmp') do Inc(ID); SaveScreenshot(Path + '(' + IntToStr(ID) + ').bmp'); end else SaveScreenshot(Path); end; begin SaveScreenshot2(ScreenPath + 'sunk.bmp'); SaveScreenshot2(ScreenPath + 'sunk'); // Just to show that both ways work, without/with ".bmp" end. Quote Link to comment Share on other sites More sharing options...
Janilabo Posted December 1, 2012 Share Posted December 1, 2012 (edited) Here is version that is based on PregReplace (filters out other formats, just like SCAR's SaveScreenshot): SaveScreenshot2 (Local ID): procedure SaveScreenshot2(Path: string); var ID: Integer; tmp: string; begin if (Path <> '') then begin tmp := PregReplace('/.([^.]*)$/', '', Path); if (tmp <> '') then Path := tmp; if FileExists(Path + '.bmp') then begin while FileExists(Path + '(' + IntToStr(ID) + ').bmp') do Inc(ID); SaveScreenshot(Path + '(' + IntToStr(ID) + ').bmp'); end else SaveScreenshot(Path + '.bmp'); end; end; begin SaveScreenshot2(ScreenPath + 'sunk.jpeg'); SaveScreenshot2(Screenpath + 'sunk.bmp'); SaveScreenshot2(ScreenPath + 'sunk.png'); SaveScreenshot2(ScreenPath + 'sunk.'); SaveScreenshot2(Screenpath + 'sunk'); end. ..and... SaveScreenshot2 (Global ID): var ID: Integer; procedure SaveScreenshot2(Path: string); var tmp: string; begin if (Path <> '') then begin tmp := PregReplace('/.([^.]*)$/', '', Path); if (tmp <> '') then Path := tmp; if FileExists(Path + '.bmp') then begin while FileExists(Path + '(' + IntToStr(ID) + ').bmp') do Inc(ID); SaveScreenshot(Path + '(' + IntToStr(ID) + ').bmp'); end else SaveScreenshot(Path + '.bmp'); end; end; begin SaveScreenshot2(ScreenPath + 'sunk.jpeg'); SaveScreenshot2(Screenpath + 'sunk.bmp'); SaveScreenshot2(ScreenPath + 'sunk.png'); SaveScreenshot2(ScreenPath + 'sunk.'); SaveScreenshot2(Screenpath + 'sunk'); end. ..and... SaveScreenshotEx2 (Local ID): procedure SaveScreenshotEx2(Path: string; XS, YS, XE, YE: Integer); var ID: Integer; tmp: string; begin if (Path <> '') then begin tmp := PregReplace('/.([^.]*)$/', '', Path); if (tmp <> '') then Path := tmp; if FileExists(Path + '.bmp') then begin while FileExists(Path + '(' + IntToStr(ID) + ').bmp') do Inc(ID); SaveScreenshotEx(Path + '(' + IntToStr(ID) + ').bmp', XS, YS, XE, YE); end else SaveScreenshotEx(Path + '.bmp', XS, YS, XE, YE); end; end; begin SaveScreenshotEx2(ScreenPath + 'sunk.jpeg', 0, 0, 100, 100); SaveScreenshotEx2(Screenpath + 'sunk.bmp', 0, 0, 100, 100); SaveScreenshotEx2(ScreenPath + 'sunk.png', 0, 0, 100, 100); SaveScreenshotEx2(ScreenPath + 'sunk.', 0, 0, 100, 100); SaveScreenshotEx2(Screenpath + 'sunk', 0, 0, 100, 100); end. ..and... SaveScreenshotEx2 (Global ID): var ID: Integer; procedure SaveScreenshotEx2(Path: string; XS, YS, XE, YE: Integer); var tmp: string; begin if (Path <> '') then begin tmp := PregReplace('/.([^.]*)$/', '', Path); if (tmp <> '') then Path := tmp; if FileExists(Path + '.bmp') then begin while FileExists(Path + '(' + IntToStr(ID) + ').bmp') do Inc(ID); SaveScreenshotEx(Path + '(' + IntToStr(ID) + ').bmp', XS, YS, XE, YE); end else SaveScreenshotEx(Path + '.bmp', XS, YS, XE, YE); end; end; begin SaveScreenshotEx2(ScreenPath + 'sunk.jpeg', 0, 0, 100, 100); SaveScreenshotEx2(Screenpath + 'sunk.bmp', 0, 0, 100, 100); SaveScreenshotEx2(ScreenPath + 'sunk.png', 0, 0, 100, 100); SaveScreenshotEx2(ScreenPath + 'sunk.', 0, 0, 100, 100); SaveScreenshotEx2(Screenpath + 'sunk', 0, 0, 100, 100); end. Edited December 1, 2012 by Janilabo Quote Link to comment Share on other sites More sharing options...
LordJashin Posted December 1, 2012 Share Posted December 1, 2012 (edited) Or you could make it take a screenshot if a certain boolean variable is true. Then use that ID thing Jani was talking about. [scar] var B: Boolean; procedure SaveScreenshot2(Path: string); var ID: Integer; tmp: string; begin if (Path <> '') then begin tmp := PregReplace('/.([^.]*)$/', '', Path); if (tmp <> '') then Path := tmp; if FileExists(Path + '.bmp') then begin while FileExists(Path + '(' + IntToStr(ID) + ').bmp') do Inc(ID); SaveScreenshot(Path + '(' + IntToStr(ID) + ').bmp'); end else SaveScreenshot(Path + '.bmp'); end; end; begin if B then SaveScreenshot2('PathToBmp.bmp'); end. [/scar] You could also use OSI's built in logging, and screenshot taking capabilities. As illustrated in this testing file i made for it - https://github.com/OSI1/OSI1/blob/master/Divi/Testing/LoggingFunctions.scar I think MSSL has some version of this too. Edited December 1, 2012 by LordJashin Quote Link to comment Share on other sites More sharing options...
Janilabo Posted December 3, 2012 Share Posted December 3, 2012 Here's improved versions, that capture the client before going through to get the ID for image, so there's no delay with screenshot. I also added boolean type for rewriting if file already exists (if rewriteExisting = false, it will add "image_name(*)", else it will rewrite "image_name"). Made em functions, they return true if screenshot was succesfully saved. SaveScreenshot2() function SaveScreenshot2(Path: string; rewriteExisting: Boolean): Boolean; var ID: Integer; tmp: string; bmp: TSCARBitmap; begin if (Path <> '') then try bmp := GetClient.Capture; tmp := PregReplace('/.([^.]*)$/', '', Path); if (tmp <> '') then Path := tmp; case (rewriteExisting or not FileExists(Path + '.bmp')) of False: begin while FileExists(Path + '(' + IntToStr(ID) + ').bmp') do Inc(ID); Result := bmp.SaveToBMP(Path + '(' + IntToStr(ID) + ').bmp'); end; True: Result := bmp.SaveToBMP(Path + '.bmp'); end; finally bmp.Free; end; end; SaveScreenshotEx2() function SaveScreenshotEx2(Path: string; XS, YS, XE, YE: Integer; rewriteExisting: Boolean): Boolean; var ID: Integer; tmp: string; bmp: TSCARBitmap; begin if (Path <> '') then try bmp := GetClient.CaptureEx(XS, YS, XE, YE); tmp := PregReplace('/.([^.]*)$/', '', Path); if (tmp <> '') then Path := tmp; case (rewriteExisting or not FileExists(Path + '.bmp')) of False: begin while FileExists(Path + '(' + IntToStr(ID) + ').bmp') do Inc(ID); Result := bmp.SaveToBMP(Path + '(' + IntToStr(ID) + ').bmp'); end; True: Result := bmp.SaveToBMP(Path + '.bmp'); end; finally bmp.Free; end; end; Use em like this: begin SaveScreenshotEx2(Screenpath + 'test', True); // This rewrites the image file. SaveScreenshot2(Screenpath + 'test.bmp', False); // This doesn't rewrite the image file. end. -Jani Quote Link to comment Share on other sites More sharing options...
seafight17 Posted December 3, 2012 Author Share Posted December 3, 2012 thank you very much it works perfectly!! Quote Link to comment Share on other sites More sharing options...
Janilabo Posted December 3, 2012 Share Posted December 3, 2012 thank you very much it works perfectly!!Glad to hear, sf17! -Jani Quote Link to comment Share on other sites More sharing options...