Author Topic: Save Image Section  (Read 3285 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Save Image Section
« on: September 06, 2020, 11:05:06 pm »
Practice with SMcNeill's SaveImage v2.3b package by creating 5 random drawings using mouse to select a screen section to save and then showing slide show of 5 saved screen sections:

Code: QB64: [Select]
  1. _TITLE "mouse down at top left corner of image section, release down and to right for section to save image section."
  2. 'Test Saveimage v2.3b by Steve McNeill BI 2020-6-11, BM 2020-6-27
  3.  
  4. '$INCLUDE:'SaveImage.BI'
  5.  
  6. CONST SaveTextAs256Color = 0 'Flag to Save as 256 color file or 32-bit color file, when converting SCREEN 0 to an image
  7. '                             Set to TRUE (any non-zero value) to save text screens in 256 color mode.
  8. '                             Set to FALSE (zero) to save text screens in 32-bit color mode.
  9.  
  10. SCREEN _NEWIMAGE(800, 600, 32)
  11. _DELAY .25
  12.  
  13. LOCATE 5, 1
  14. yCP 7, "***  SaveImage Section ***         b+ 2020-09-06"
  15. yCP 10, "Testing SaveImage v2.3 by saving 5 screen sections of randomly drawn boxes."
  16. yCP 12, "Mouse down at the top, left corner of your selection, drag mouse down and left to"
  17. yCP 14, "bottom, right of your selection. As soon as you release button this app should "
  18. yCP 16, "show the section you selected centered in the middle of the screen."
  19. yCP 18, "we will do this 5 times and then show a little slide show of our selections :)"
  20. yCP 21, "press any to continue..."
  21.  
  22. FOR i& = 1 TO 5
  23.     'draw some junk to save an image section
  24.     image& = _NEWIMAGE(_WIDTH, _HEIGHT, 32)
  25.     CLS
  26.     FOR i = 1 TO 100
  27.         LINE (RND * _WIDTH, RND * _HEIGHT)-STEP(RND * 100 + 10, RND * 100 + 10), _RGB32(RND * 255, RND * 256, RND * 256), BF
  28.     NEXT
  29.     PRINT "Test Section #" + _TRIM$(STR$(i&))
  30.     _PUTIMAGE , 0, image&
  31.     COLOR , &HFF000000: CLS
  32.     saveImageFile$ = "Test Save Image(" + _TRIM$(STR$(i&)) + ").png"
  33.     IF _FILEEXISTS(saveImageFile$) THEN KILL saveImageFile$
  34.     DO
  35.         _PUTIMAGE , image&, 0 'cls with image
  36.         WHILE _MOUSEINPUT: WEND
  37.         mb = _MOUSEBUTTON(1): mx = _MOUSEX: my = _MOUSEY
  38.         IF mb THEN
  39.             sx = mx: sy = my 'start mouse
  40.             WHILE mb
  41.                 CLS
  42.                 _PUTIMAGE , image&, 0
  43.                 WHILE _MOUSEINPUT: WEND
  44.                 mb = _MOUSEBUTTON(1): mx = _MOUSEX: my = _MOUSEY
  45.                 LINE (sx, sy)-(mx, my), , B
  46.                 LINE (sx - 1, sy - 1)-(mx + 1, my + 1), &HFF000000, B
  47.                 _DISPLAY
  48.                 _LIMIT 60
  49.             WEND
  50.             fx = mx - 1: fy = my 'finish mouse
  51.             'Result = SaveImage(exportimage(i), l&, 0, 0, _WIDTH(l&) - 1, _HEIGHT(l&) - 1)
  52.             Result = SaveImage(saveImageFile$, 0, sx + 1, sy + 1, fx - 1, fy - 1)
  53.             IF Result = -1 THEN 'file already found on drive
  54.                 PRINT "Image Section Saved to " + saveImageFile$ + ", we will load it in 4 secs."
  55.                 EXIT DO
  56.             ELSE
  57.                 PRINT "Error #" + _TRIM$(STR$(Result)) + " occurred image not saved, goodbye."
  58.                 END
  59.             END IF
  60.             _DISPLAY
  61.             _DELAY 4
  62.             END
  63.         END IF
  64.         _DISPLAY
  65.         _LIMIT 60
  66.     LOOP
  67.     CLS
  68.     L& = _LOADIMAGE(saveImageFile$)
  69.     IF L& < -1 THEN
  70.         _PUTIMAGE ((_WIDTH - _WIDTH(L&)) / 2, (_HEIGHT - _HEIGHT(L&)) / 2), L&, 0
  71.     ELSE
  72.         PRINT "Sorry, "; saveImageFile$; " failed to load."
  73.     END IF
  74.     _DISPLAY
  75.     _DELAY 4
  76.     _FREEIMAGE image&
  77.     _FREEIMAGE L&
  78. FOR i& = 1 TO 5
  79.     saveImageFile$ = "Test Save Image(" + _TRIM$(STR$(i&)) + ").png"
  80.     CLS
  81.     L& = _LOADIMAGE(saveImageFile$)
  82.     IF L& < -1 THEN
  83.         _PUTIMAGE ((_WIDTH - _WIDTH(L&)) / 2, (_HEIGHT - _HEIGHT(L&)) / 2), L&, 0
  84.     ELSE
  85.         PRINT "Sorry, "; saveImageFile$; " failed to load."
  86.     END IF
  87.     _DISPLAY
  88.     _DELAY 4
  89.     _FREEIMAGE L&
  90.  
  91. SUB yCP (y, s$) 'for xmax pixel wide graphics screen Center Print at pixel y row
  92.     _PRINTSTRING ((_WIDTH - LEN(s$) * 8) / 2, y * 16), s$
  93.  
  94.  
  95. '$INCLUDE:'SaveImage.BM'
  96.  

Zip with BI and massive BM
* Save Image Section Test.zip (Filesize: 18.62 KB, Downloads: 202)