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


{{PageSyntax}}
: handle&amp; = _LOADIMAGE&amp; (''filename$''[, ''mode&amp;''])


{{PageDescription}}
* File types supported:  BMP, JPG, PNG, GIF, PNM, XPM, XCF, PCX, TIF, LBM, and TGA. A path can also be given.
* The ''Mode&amp;'' can designate 256(8 bit) or 32 bit color. Omit to use the current graphic screen settings.
* Some images may not load when a ''mode'' value is designated. Try loading it without a ''mode'' designation.
* 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]].
* '''In text [[SCREEN]] 0 ''mode&amp;'' 32 must be designated!''' When loading an [[_ICON]] image use 32 for the mode also.
* Returns -1 as an invalid handle if it could not load the image. Valid {{KW|LONG}} handle returns are less than -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]].'''
* '''It is IMPORTANT to free unused or discarded images with [[_FREEIMAGE]] to prevent CPU memory overflow errors!'''
* '''QB64 currently does not support icon files! A bad handle value will occur using _LOADIMAGE! See [[_ICON]] example 2.''' 


{{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&amp; = {{Cl|_LOADIMAGE}}(&quot;mypic.jpg&quot;) 
{{Cl|_PUTIMAGE}}, i&amp; '' ''
{{CodeEnd}}


''Example 2:'' Already in SCREEN 13 but want to load an 8-bit image and adopt its 
palette as the current palette:
{{CodeStart}} '' ''
{{Cl|SCREEN (statement)|SCREEN}} 13
i&amp; = {{Cl|_LOADIMAGE}}(&quot;mypic256col.bmp&quot;, 256)
{{Cl|_COPYPALETTE}} i&amp;, 0
{{Cl|_PUTIMAGE}}, i&amp; '' ''
{{CodeEnd}}


''Example 3:'' Want to display an image in 32-bit color using its resolution as a program screen:
{{CodeStart}} '' ''
i&amp; = {{Cl|_LOADIMAGE}}(&quot;mypic.jpg&quot;, 32)
{{Cl|SCREEN (statement)|SCREEN}} i&amp; '' ''
{{CodeEnd}}


''Example 4:'' [[DRAW]]ing and rotating an image 360 degrees using Turn Angle. [[POINT]] is used to read the invisible image source.
{{CodeStart}}
{{Cl|SCREEN (statement)|SCREEN}} {{Cl|_NEWIMAGE}}(800, 600, 32)
img&amp; = {{Cl|_LOADIMAGE}}(&quot;QB64.PNG&quot;)                           'load the image file to be drawn

wide% = {{Cl|_WIDTH (function)|_WIDTH}}(img&amp;): deep% = {{Cl|_HEIGHT}}(img&amp;)
TLC$ = &quot;BL&quot; + {{Cl|STR$}}(wide% \ 2) + &quot;BU&quot; + {{Cl|STR$}}(deep% \ 2)  'start draw at top left corner
RET$ = &quot;BD BL&quot; + {{Cl|STR$}}(wide%)                            'return to left side of image
{{Cl|_SOURCE}} img&amp;
{{Cl|_DEST}} 0
DO
  {{Cl|FOR...NEXT|FOR}} angle% = 0 {{Cl|TO}} 360 {{Cl|STEP}} 15
    {{Cl|CLS}}
    {{Cl|DRAW}} &quot;BM400, 300&quot; + &quot;TA=&quot; + {{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}} &quot;C&quot; + {{Cl|STR$}}({{Cl|POINT}}(x, y)) + &quot;R1&quot;            '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$}} &gt; &quot;&quot; '' ''
{{CodeEnd}}
{{small|Code by Ted Weissgerber}}
:''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.


''See Examples:''
*{{KW|SAVEIMAGE}} (QB64 Image to Bitmap SUB by Galleon)

*{{KW|Program ScreenShots}} (Member program for legacy screen modes)

* {{KW|ThirtyTwoBit SUB}} (QB64 Image area to bitmap)


{{PageSeeAlso}}
*[[_FREEIMAGE]], [[_PUTIMAGE]], [[_NEWIMAGE]], [[_COPYIMAGE]], [[_PRINTIMAGE]] (printer)
*[[_PALETTECOLOR (function)]], [[_COPYPALETTE]], [[_ICON]]
*[[SCREEN (statement)]]
*[[Bitmaps]], [[Icons and Cursors]], [[GIF Images]]


{{PageNavigation}}