Difference between revisions of "LOADIMAGE"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
Tag: visualeditor
 
(41 intermediate revisions by 2 users not shown)
Line 1: Line 1:
The '''_LOADIMAGE''' function returns an image handle for a graphic file image.  
+
{{DISPLAYTITLE:_LOADIMAGE}}
 +
 
 +
The [[_LOADIMAGE]] function loads an image into memory and returns valid [[LONG]] image handle values that are less than -1.  
  
  
 
{{PageSyntax}}
 
{{PageSyntax}}
: handle& = _LOADIMAGE& (filename$[, mode&])
+
 
 +
:{{Parameter|handle&}} = [[_LOADIMAGE]]({{Parameter|filename$}}[, {{Parameter|mode%}}])
 +
 
 +
 
 +
{{Parameters}}
 +
 
 +
*{{Parameter|filename$}} is literal or variable [[STRING]] file name value.
 +
*Optional {{Parameter|mode%}} [[INTEGER]] values can be:
 +
**256 = 8-bit (256-color, ''QB64 versions prior to 1.000'')
 +
**32 = 32-bit
 +
**33 = hardware image
  
  
 
{{PageDescription}}
 
{{PageDescription}}
* File types supported:  BMP, JPG, PNG, GIF, PNM, XPM, XCF, PCX, TIF, LBM, TGA,
 
* Mode& can be 256 colors or 32 bit or omitted if using the current screen mode.
 
* When you are in SCREEN 0 then a mode& '''must''' be used. When loading an [[_ICON]] use 32 for the mode.
 
* Returns -1 as an invalid handle if it could not load the image. Valid {{KW|LONG}} handle returns are less than -1.
 
* It is IMPORTANT to free unused or discarded images with {{KW|_FREEIMAGE}} to prevent memory overflow errors!
 
  
 +
*Various common image file formats supported, like BMP, JPG, PNG, etc. A path can also be given.
 +
*The {{Parameter|mode%}} can designate 256 (8-bit - versions prior to 1.000), 32-bit color or 33 ('''version 1.000 and up'''). Omit to use the current graphic screen settings.
 +
*Mode 33 images are '''hardware''' accelerated and are created using [[_LOADIMAGE]] or [[_COPYIMAGE]] ('''version 1.000 and up''').
 +
*Loaded images can be read invisibly using [[POINT]]. Image coordinates start at 0 up to the [[_WIDTH (function)|_WIDTH]] - 1 and [[_HEIGHT]] - 1.
 +
*Images can be made into a program [[SCREEN (statement)|SCREEN]] or page adopting the size and palette settings or placed using [[_PUTIMAGE]].
 +
*Returns -1 as an invalid handle if it can't load the image. Valid [[LONG]] handle returns are less than -1 ({{Parameter|handle&}} < -1).
 +
*Valid images only need to be loaded once. The handle can be used repeatedly until freed.
 +
*'''Images are not deallocated when the [[SUB]] or [[FUNCTION]] they are created in ends. Free them with [[_FREEIMAGE]].'''
  
{{PageExamples}}
 
''Example 1:''  Already in SCREEN 13 and want computer to match the 32-bit jpg/etc.
 
colors to the current palette:
 
{{CodeStart}} '' ''
 
{{Cl|SCREEN (statement)|SCREEN}} 13
 
i& = {{Cl|_LOADIMAGE}}("mypic.jpg")
 
{{Cl|_PUTIMAGE}}, i& '' ''
 
{{CodeEnd}}
 
  
 +
{{PageErrors}}
  
''Example 2:'' Already in SCREEN 13 but want to load an 8-bit image and adopt its
+
*Some picture file images may not load when a {{Parameter|mode%}} value is designated. Try loading it without a {{Parameter|mode%}} designation.
palette as the current palette:
+
*'''It is important to free unused or discarded images with [[_FREEIMAGE]] to prevent CPU memory overflow errors.'''
{{CodeStart}} '' ''
+
*'''In text-only [[SCREEN]] 0, {{Parameter|mode%}} 32 must be specified.''' When loading an [[_ICON]] image use 32 for the {{Parameter|mode%}} too.
{{Cl|SCREEN (statement)|SCREEN}} 13
 
i& = {{Cl|_LOADIMAGE}}("mypic256col.bmp", 256)
 
{{Cl|_COPYPALETTE}} i&, 0
 
{{Cl|_PUTIMAGE}}, i& '' ''
 
{{CodeEnd}}
 
  
  
''Example 3:'' Want to display an image in 32-bit color using its resolution:
+
{{PageExamples}}
 +
''Example 1:'' To display an image in 32-bit color using its resolution as a program screen:
 
{{CodeStart}} '' ''
 
{{CodeStart}} '' ''
 
i& = {{Cl|_LOADIMAGE}}("mypic.jpg", 32)
 
i& = {{Cl|_LOADIMAGE}}("mypic.jpg", 32)
Line 41: Line 45:
  
  
''See Examples:''
+
''Example 2:'' [[DRAW]]ing and rotating an image 360 degrees using Turn Angle. [[POINT]] is used to read the invisible image source.
*{{KW|SAVEIMAGE}} (QB64 Image to Bitmap SUB by Galleon)
+
{{CodeStart}}
 +
{{Cl|SCREEN (statement)|SCREEN}} {{Cl|_NEWIMAGE}}(800, 600, 32)
 +
img& = {{Cl|_LOADIMAGE}}("QB64.PNG")                          'load the image file to be drawn
  
*{{KW|Program ScreenShots}} (Member program for legacy screen modes)
+
wide% = {{Cl|_WIDTH (function)|_WIDTH}}(img&): deep% = {{Cl|_HEIGHT}}(img&)
 +
TLC$ = "BL" + {{Cl|STR$}}(wide% \ 2) + "BU" + {{Cl|STR$}}(deep% \ 2)  'start draw at top left corner
 +
RET$ = "BD BL" + {{Cl|STR$}}(wide%)                            'return to left side of image
 +
{{Cl|_SOURCE}} img&
 +
{{Cl|_DEST}} 0
 +
DO
 +
  {{Cl|FOR...NEXT|FOR}} angle% = 0 {{Cl|TO}} 360 {{Cl|STEP}} 15
 +
    {{Cl|CLS}}
 +
    {{Cl|DRAW}} "BM400, 300" + "TA=" + {{Cl|VARPTR$}}(angle%) + TLC$
 +
    {{Cl|FOR...NEXT|FOR}} y = 0 {{Cl|TO}} deep% - 1
 +
      {{Cl|FOR...NEXT|FOR}} x = 0 {{Cl|TO}} wide% - 1
 +
        {{Cl|DRAW}} "C" + {{Cl|STR$}}({{Cl|POINT}}(x, y)) + "R1"            'color and DRAW each pixel
 +
      {{Cl|NEXT}}
 +
      {{Cl|DRAW}} RET$
 +
    {{Cl|NEXT}}
 +
    {{Cl|_DISPLAY}}                        'NOTE: CPU usage will be HIGH!
 +
  {{Cl|NEXT}}
 +
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} > "" '' ''
 +
{{CodeEnd}}
 +
{{small|Code by Ted Weissgerber}}
  
* {{KW|ThirtyTwoBit SUB}} (QB64 Image area to bitmap)
+
:''NOTE:'' The ''QB64.PNG'' file picturing the QB64 bee can saved from the top of the [http://www.qb64.net/forum/index.php QB64 forum]. Speed varies with image size.
  
  
 +
===More examples===
  
{{PageSeeAlso}}
+
*[[SAVEIMAGE]] (QB64 Image to Bitmap SUB by Galleon)
*{{KW|_FREEIMAGE}}, {{KW|_PUTIMAGE}}, {{KW|_NEWIMAGE}}, {{KW|_COPYIMAGE}}, {{KW|_PRINTIMAGE}} (printer)
+
*[[Program ScreenShots]] (Member-contributed program for legacy screen modes)
*{{KW|_PALETTECOLOR (function)}}, {{KW|_COPYPALETTE}}, {{KW|_ICON}}
+
*[[ThirtyTwoBit SUB]] (QB64 Image area to bitmap)
*{{KW|SCREEN (statement)}}
 
*{{KW|Bitmaps}}, {{KW|Icons and Cursors}}, {{KW|GIF Images}}, {{KW|JPG Images}}
 
  
  
 +
{{PageSeeAlso}}
  
 +
*[[_FREEIMAGE]], [[_ICON]]
 +
*[[_PUTIMAGE]], [[_MAPTRIANGLE]]
 +
*[[_NEWIMAGE]], [[_COPYIMAGE]]
 +
*[[_PRINTIMAGE]] (printer)
 +
*[[_PALETTECOLOR (function)]], [[_COPYPALETTE]], [[_ICON]]
 +
*[[SCREEN (statement)]]
 +
*[[Hardware images]]
 +
*[[Bitmaps]], [[Icons and Cursors]], [[GIF Images]]
  
  
 
{{PageNavigation}}
 
{{PageNavigation}}

Latest revision as of 07:37, 21 February 2020


The _LOADIMAGE function loads an image into memory and returns valid LONG image handle values that are less than -1.


Syntax

handle& = _LOADIMAGE(filename$[, mode%])


Parameters

  • filename$ is literal or variable STRING file name value.
  • Optional mode% INTEGER values can be:
    • 256 = 8-bit (256-color, QB64 versions prior to 1.000)
    • 32 = 32-bit
    • 33 = hardware image


Description

  • Various common image file formats supported, like BMP, JPG, PNG, etc. A path can also be given.
  • The mode% can designate 256 (8-bit - versions prior to 1.000), 32-bit color or 33 (version 1.000 and up). Omit to use the current graphic screen settings.
  • Mode 33 images are hardware accelerated and are created using _LOADIMAGE or _COPYIMAGE (version 1.000 and up).
  • Loaded images can be read invisibly using POINT. Image coordinates start at 0 up to the _WIDTH - 1 and _HEIGHT - 1.
  • Images can be made into a program SCREEN or page adopting the size and palette settings or placed using _PUTIMAGE.
  • Returns -1 as an invalid handle if it can't load the image. Valid LONG handle returns are less than -1 (handle& < -1).
  • Valid images only need to be loaded once. The handle can be used repeatedly until freed.
  • Images are not deallocated when the SUB or FUNCTION they are created in ends. Free them with _FREEIMAGE.


Errors

  • Some picture file images may not load when a mode% value is designated. Try loading it without a mode% designation.
  • It is important to free unused or discarded images with _FREEIMAGE to prevent CPU memory overflow errors.
  • In text-only SCREEN 0, mode% 32 must be specified. When loading an _ICON image use 32 for the mode% too.


Examples

Example 1: To display an image in 32-bit color using its resolution as a program screen:

i& = _LOADIMAGE("mypic.jpg", 32) SCREEN i&


Example 2: DRAWing and rotating an image 360 degrees using Turn Angle. POINT is used to read the invisible image source.

SCREEN _NEWIMAGE(800, 600, 32) img& = _LOADIMAGE("QB64.PNG") 'load the image file to be drawn wide% = _WIDTH(img&): deep% = _HEIGHT(img&) TLC$ = "BL" + STR$(wide% \ 2) + "BU" + STR$(deep% \ 2) 'start draw at top left corner RET$ = "BD BL" + STR$(wide%) 'return to left side of image _SOURCE img& _DEST 0 DO FOR angle% = 0 TO 360 STEP 15 CLS DRAW "BM400, 300" + "TA=" + VARPTR$(angle%) + TLC$ FOR y = 0 TO deep% - 1 FOR x = 0 TO wide% - 1 DRAW "C" + STR$(POINT(x, y)) + "R1" 'color and DRAW each pixel NEXT DRAW RET$ NEXT _DISPLAY 'NOTE: CPU usage will be HIGH! NEXT LOOP UNTIL INKEY$ > ""

Code by Ted Weissgerber
NOTE: The QB64.PNG file picturing the QB64 bee can saved from the top of the QB64 forum. Speed varies with image size.


More examples


See also



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