Difference between revisions of "LOADIMAGE"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
imported>Clippy
m
Line 10: Line 10:
 
* The ''Mode&'' can designate 256(8 bit) or 32 bit color. Omit to use the current screen settings.
 
* The ''Mode&'' can designate 256(8 bit) or 32 bit color. Omit to use the current screen settings.
 
* Some images may not load when a ''mode'' value is designated. Try loading it without a ''mode'' designation.
 
* 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]].
 
* Images can be made into a program [[SCREEN (statement)|SCREEN]] or page adopting the size and palette settings or placed using [[_PUTIMAGE]].
 
* When you are in SCREEN 0 a ''mode&'' '''must''' be designated. When loading an [[_ICON]] use 32 for the mode.
 
* When you are in SCREEN 0 a ''mode&'' '''must''' be designated. When loading an [[_ICON]] use 32 for the mode.
Line 43: Line 44:
 
{{CodeEnd}}
 
{{CodeEnd}}
  
 +
 +
''Example 4:'' Rotating an image 360 degrees using [[DRAW]] and Turn Angle.
 +
{{CodeStart}}
 +
{{Cl|SCREEN (statement)|SCREEN}} {{Cl|_NEWIMAGE}}(800, 600, 32)
 +
 +
img& = {{Cl|_LOADIMAGE}}("QB64bee.PNG")
 +
wide% = {{Cl|_WIDTH (function)|_WIDTH}}(img&): deep% = {{Cl|_HEIGHT}}(img&)
 +
TLC$ = "BL" + {{Cl|STR$}}(wide% \ 2) + "BU" + {{Cl|STR$}}(deep% \ 2)
 +
RET$ = "BD BL" + {{Cl|STR$}}(wide%)
 +
{{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"
 +
      {{Cl|NEXT}}
 +
      {{Cl|DRAW}} RET$
 +
    {{Cl|NEXT}}
 +
    {{Cl|_DISPLAY}}
 +
  {{Cl|NEXT}}
 +
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} > "" '' ''
 +
{{CodeEnd}}
 +
{{small|Code by Ted Weissgerber}}
 +
:''NOTE:'' The ''QB64.PNG'' file picturing the QB64 bee can saved from the top of the QB64 forum.
  
 
''See Examples:''
 
''See Examples:''

Revision as of 00:42, 27 February 2011

The _LOADIMAGE function loads an image into memory and returns an image handle for a graphic file image.


Syntax

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


Description

  • File types supported: BMP, JPG, PNG, GIF, PNM, XPM, XCF, PCX, TIF, LBM, and TGA. A path can also be given.
  • The Mode& can designate 256(8 bit) or 32 bit color. Omit to use the current 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 - 1 and _HEIGHT - 1.
  • Images can be made into a program SCREEN or page adopting the size and palette settings or placed using _PUTIMAGE.
  • When you are in SCREEN 0 a mode& must be designated. When loading an _ICON use 32 for the mode.
  • Returns -1 as an invalid handle if it could not load the image. Valid LONG handle returns are less than -1.
  • Valid images only need to be loaded ONCE! The handle can be used repeatedly until freed.
  • It is IMPORTANT to free unused or discarded images with _FREEIMAGE to prevent CPU memory overflow errors!


Examples

Example 1: Already in SCREEN 13 and want computer to match the 32-bit jpg/etc. colors to the current palette:

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


Example 2: Already in SCREEN 13 but want to load an 8-bit image and adopt its palette as the current palette:

SCREEN 13 i& = _LOADIMAGE("mypic256col.bmp", 256) _COPYPALETTE i&, 0 _PUTIMAGE, i&


Example 3: Want to display an image in 32-bit color using its resolution as a program screen:

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


Example 4: Rotating an image 360 degrees using DRAW and Turn Angle.

SCREEN _NEWIMAGE(800, 600, 32) img& = _LOADIMAGE("QB64bee.PNG") wide% = _WIDTH(img&): deep% = _HEIGHT(img&) TLC$ = "BL" + STR$(wide% \ 2) + "BU" + STR$(deep% \ 2) RET$ = "BD BL" + STR$(wide%) _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" NEXT DRAW RET$ NEXT _DISPLAY 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.

See Examples:

  • SAVEIMAGE (QB64 Image to Bitmap SUB by Galleon)


See also



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