Author Topic: Screen Print, Windows 10, Logitech K850 Keyboard and QB64  (Read 5472 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Screen Print, Windows 10, Logitech K850 Keyboard and QB64
« Reply #15 on: December 30, 2020, 05:00:04 pm »
A quick demo of SaveImage in use, for you:

Code: QB64: [Select]
  1. '$INCLUDE:'SaveImage.BI'
  2.  
  3.  
  4. SCREEN _NEWIMAGE(640, 480, 32)
  5.  
  6. 'draw something
  7. FOR i = 1 TO 100
  8.     LINE (RND * 640, RND * 480)-(RND * 640, RND * 480), _RGB32(RND * 255, RND * 255, RND * 255), B
  9.  
  10. file$ = "temp.bmp" 'the file to save to
  11. image& = _DISPLAY 'the file handle which you want to save
  12. startx = 0 'the x/y coordinate of the top left portion of the screen which you want to capture
  13. starty = 0
  14. stopx = _WIDTH 'the x/y coordinate of the bottom right portion of the screen which you want to capture
  15. stopy = _HEIGHT
  16.  
  17. result = SaveImage(file$, image&, startx, starty, stopx, stopy)
  18. PRINT result 'this gives us error codes, in case something goes wrong.
  19. '-1, in this case, says "All is good!  No glitch in the export of a bmp file."
  20.  
  21.  
  22. file$ = "temp.png" 'if we change the extension, we change what we export to disk
  23.  
  24. result = SaveImage(file$, image&, startx, starty, stopx, stopy)
  25. PRINT result 'this gives us error codes, in case something goes wrong.
  26.  
  27. 'just by changing the extension, we can save a screenshot in BMP, PNG, JPG, GIF format.
  28.  
  29.  
  30. SCREEN 0 'A text screen
  31. FOR i = 0 TO 15
  32.     COLOR i, 15 - i
  33.     PRINT "COLOR "; i, 15 - i
  34.  
  35. result = SaveImage("textscreen.gif", _DISPLAY, 0, 0, _WIDTH, _HEIGHT)
  36. PRINT result
  37.  
  38. 'And, as you can see, we work perfectly fine with SCREEN 0 TEXT images as well.
  39.  
  40.  
  41. '$INCLUDE:'SaveImage.BM'


Usage is as simple as :

$INCLUDE the BI file.

result = SaveImage(file$, screen, x1, y1, x2, y2)

$INCLUDE the BM file.


Works on all screen modes (including text screens), and automatically dithers to best image quality for GIFs or 256 color images, if necessary.  Can save in BMP, JPG, GIF, or PNG format, depending on what you need/want (just change the extension on your file  name to change output file type).

It really is that simple.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!