Difference between revisions of "NEWIMAGE"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
imported>Clippy
m
Line 20: Line 20:
 
''Example 1:'' Shrinking a SCREEN 0 text window's size:
 
''Example 1:'' Shrinking a SCREEN 0 text window's size:
  
{{CodeStart}}
+
{{CodeStart}} '' ''
 
+
{{Cl|SCREEN (statement)|SCREEN}} {{Cl|_NEWIMAGE}}(28, 25, 0) '' ''
{{Cl|SCREEN (statement)|SCREEN}} {{Cl|_NEWIMAGE}}(28, 25, 0)  
 
 
 
 
{{CodeEnd}}
 
{{CodeEnd}}
  
 
''Example 2:'' Creating an 800 by 600 window version of SCREEN 12 with 256 colors (text 37 X 100):
 
''Example 2:'' Creating an 800 by 600 window version of SCREEN 12 with 256 colors (text 37 X 100):
{{CodeStart}}
+
{{CodeStart}} '' ''
 
 
 
handle& = {{Cl|_NEWIMAGE}}(800, 600, 256)  
 
handle& = {{Cl|_NEWIMAGE}}(800, 600, 256)  
{{Cl|SCREEN (statement)|SCREEN}} handle&
+
{{Cl|SCREEN (statement)|SCREEN}} handle& '' ''
 
 
 
{{CodeEnd}}
 
{{CodeEnd}}
  
 
''Example 3:'' Setting up a SCREEN with _NEWIMAGE for page flipping in QB64.
 
''Example 3:'' Setting up a SCREEN with _NEWIMAGE for page flipping in QB64.
 
+
{{CodeStart}} '' ''
{{CodeStart}}  
+
SCREEN _NEWIMAGE(640, 480, 256), , 1, 0 '' ''
 
 
SCREEN _NEWIMAGE(640, 480, 256), , 1, 0
 
 
 
 
{{CodeEnd}}
 
{{CodeEnd}}
  
Line 45: Line 38:
  
 
''Example 4:'' Switching between two different SCREEN modes
 
''Example 4:'' Switching between two different SCREEN modes
{{CodeStart}}
+
{{CodeStart}} '' ''
 
 
 
_TITLE "Switching SCREEN modes"
 
_TITLE "Switching SCREEN modes"
 
SCREEN _NEWIMAGE (800, 600, 256)
 
SCREEN _NEWIMAGE (800, 600, 256)
Line 73: Line 65:
  
 
SCREEN mode2&  'back to small window
 
SCREEN mode2&  'back to small window
COLOR 14: LOCATE 16, 16: PRINT "LAST "
+
COLOR 14: LOCATE 16, 16: PRINT "LAST " '' ''
 
 
 
{{CodeEnd}}
 
{{CodeEnd}}
 
:''Explanation:'' The [[_DEST (function)|_DEST]] function can determine the present screen mode destination handle. The second _NEWIMAGE  handle is created using a SCREEN 13 palette(256 colors also). Each SCREEN is worked on after changing the destination with [[_DEST]] ''handle&'' statement. Images can be created before viewing them. When a key is pressed the second SCREEN created is displayed and so on.  
 
:''Explanation:'' The [[_DEST (function)|_DEST]] function can determine the present screen mode destination handle. The second _NEWIMAGE  handle is created using a SCREEN 13 palette(256 colors also). Each SCREEN is worked on after changing the destination with [[_DEST]] ''handle&'' statement. Images can be created before viewing them. When a key is pressed the second SCREEN created is displayed and so on.  

Revision as of 21:16, 31 January 2011

The _NEWIMAGE Function prepares a window image surface and returns the handle value.


Syntax

handle& = _NEWIMAGE& (width AS LONG, height AS LONG[, BPPmode AS LONG])


Description

  • Minimum screen dimensions are Width& >= 0, Height& >= 1 measured in pixels.
  • BPPmode& is either a QB type screenmode(0 to 2 or 7 to 13) or 256 colors or 32 bit(high color) compatible.
  • If BPPmode is omitted, an image will be created in the same BPP mode as the current destination image.
  • Valid LONG handle returns are less than -1. Invalid handles equal -1 so a zero value is also invalid.
  • You can create any sized window(limited by OS) using this function.
  • To view the image handle, just use SCREEN handle&. Even if another procedure changes the screen mode and clears the screen, the image can be restored when it is done by using the SCREEN handle mode.
  • Use the _COPYIMAGE function to preserve a SCREEN handle value when changing to another screen mode to restore it later.
  • It is IMPORTANT to free unused or uneeded images with _FREEIMAGE to prevent CPU memory overflow errors!


Examples

Example 1: Shrinking a SCREEN 0 text window's size:

SCREEN _NEWIMAGE(28, 25, 0)

Example 2: Creating an 800 by 600 window version of SCREEN 12 with 256 colors (text 37 X 100):

handle& = _NEWIMAGE(800, 600, 256) SCREEN handle&

Example 3: Setting up a SCREEN with _NEWIMAGE for page flipping in QB64.

SCREEN _NEWIMAGE(640, 480, 256), , 1, 0

Note: _DISPLAY may be used as a substitute for page flipping or PCOPY.

Example 4: Switching between two different SCREEN modes

_TITLE "Switching SCREEN modes" SCREEN _NEWIMAGE (800, 600, 256) mode1& = _DEST 'get current screen mode handle mode2& = _NEWIMAGE (300, 200, 13) _DEST mode2& 'prepare small window COLOR 10: LOCATE 10, 13: PRINT "mode2& = "; mode2& COLOR 13: LOCATE 16, 16: PRINT "First" _DEST mode1& 'work in main window LOCATE 5 FOR c = 1 TO 248 Color c: PRINT c; NEXT COLOR 12: LOCATE 20, 44: PRINT "mode1& = "; mode1& COLOR 11: LOCATE 30, 34: PRINT "Press a key to goto Pop-up Window" DO: SLEEP: LOOP UNTIL INKEY$ <> "" SCREEN mode2& 'switch to small window DO: SLEEP: LOOP UNTIL INKEY$ <> "" SCREEN mode1& 'back to main window COLOR 12: LOCATE 37, 43: PRINT "One more time!" DO: SLEEP: LOOP UNTIL INKEY$ <> "" SCREEN mode2& 'back to small window COLOR 14: LOCATE 16, 16: PRINT "LAST "

Explanation: The _DEST function can determine the present screen mode destination handle. The second _NEWIMAGE handle is created using a SCREEN 13 palette(256 colors also). Each SCREEN is worked on after changing the destination with _DEST handle& statement. Images can be created before viewing them. When a key is pressed the second SCREEN created is displayed and so on.
Legacy SCREEN modes can also return a _DEST value, but the value will create a handle error! To restore legacy screens get the_COPYIMAGE function value before changing screens. Then restore it using SCREEN oldmode&.


See Examples:

SAVEIMAGE (Bitmap creation)

_FILE$ (restoring previous screen)

_PIXELSIZE (GetImage function example)


See also




Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page