LOADIMAGE: Difference between revisions
Jump to navigation
Jump to search
Code by Ted Weissgerber
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:_LOADIMAGE}} | {{DISPLAYTITLE:_LOADIMAGE}} | ||
The '''_LOADIMAGE''' function loads an image into memory and returns valid [[LONG]] image handle values that are less than -1. | |||
The | |||
{{PageSyntax}} | {{PageSyntax}} | ||
: {{Parameter|handle&}} = [[_LOADIMAGE]]({{Parameter|filename$}}[, {{Parameter|mode%}}]) | |||
:{{Parameter|handle&}} = [[_LOADIMAGE]]({{Parameter|filename$}}[, {{Parameter|mode%}}]) | |||
{{PageParameters}} | {{PageParameters}} | ||
*{{Parameter|filename$}} is literal or variable [[STRING]] file name value. | *{{Parameter|filename$}} is literal or variable [[STRING]] file name value. | ||
*Optional {{Parameter|mode%}} [[INTEGER]] values can be: | *Optional {{Parameter|mode%}} [[INTEGER]] values can be: | ||
Line 20: | Line 17: | ||
{{PageDescription}} | {{PageDescription}} | ||
*Various common image file formats like JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC, PNM and PCX are supported. A path can also be given. | *Various common image file formats like JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC, PNM and PCX are supported. A path can also be given. | ||
*The {{Parameter|mode%}} parameter can be 32, 33 ('''version 1.000 and up'''), 256 or 257 ('''version 3.1.0 and up'''). Omit to use the current graphic screen settings. | *The {{Parameter|mode%}} parameter can be 32, 33 ('''version 1.000 and up'''), 256 or 257 ('''version 3.1.0 and up'''). Omit to use the current graphic screen settings. | ||
Line 33: | Line 29: | ||
=== Errors === | === Errors === | ||
*Some picture file images may not load when a {{Parameter|mode%}} value is designated. Try loading it without a {{Parameter|mode%}} designation. | *Some picture file images may not load when a {{Parameter|mode%}} value is designated. Try loading it without a {{Parameter|mode%}} designation. | ||
*'''It is important to free unused or discarded images with [[_FREEIMAGE]] to prevent CPU memory overflow errors.''' | *'''It is important to free unused or discarded images with [[_FREEIMAGE]] to prevent CPU memory overflow errors.''' | ||
*'''In text-only [[SCREEN]] 0, {{Parameter|mode%}} 32 must be specified.''' When loading an [[_ICON]] image use 32 for the {{Parameter|mode%}} too. | *'''In text-only [[SCREEN]] 0, {{Parameter|mode%}} 32 must be specified.''' When loading an [[_ICON]] image use 32 for the {{Parameter|mode%}} too. | ||
{{PageAvailability}} | |||
<!-- QB64 = a version or none, QBPE = a version or all, Platforms = yes or no --> | |||
<gallery widths="48px" heights="48px" mode="nolines"> | |||
File:Qb64.png|'''v0.800''' | |||
File:Qbpe.png|'''all''' | |||
File:Apix.png | |||
File:Win.png|'''yes''' | |||
File:Lnx.png|'''yes''' | |||
File:Osx.png|'''yes''' | |||
</gallery> | |||
<!-- Additional availability notes go below the gallery, e.g. --> | |||
* The capability to load from ''memory'' was introduced in '''QB64-PE''' ''v3.6.0''. | |||
{{PageExamples}} | {{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 46: | Line 55: | ||
{{CodeEnd}} | {{CodeEnd}} | ||
---- | |||
;Example 2:[[DRAW]]ing and rotating an image 360 degrees using Turn Angle. [[POINT]] is used to read the invisible image source. | |||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|SCREEN}} {{Cl|_NEWIMAGE}}(800, 600, 32) | {{Cl|SCREEN}} {{Cl|_NEWIMAGE}}(800, 600, 32) |
Revision as of 14:47, 19 February 2023
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:
- 32 = 32-bit image
- 33 = 32-bit hardware image
- 256 = 8-bit (256 color) image using the QB64-PE master palette
- 257 = 8-bit (256 color) image using an adaptive palette
Description
- Various common image file formats like JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC, PNM and PCX are supported. A path can also be given.
- The mode% parameter can be 32, 33 (version 1.000 and up), 256 or 257 (version 3.1.0 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).
- Mode 256 images are loaded using the QB64-PE master palette. This is the same palette that is used for 256 color screens like SCREEN 13.
- Mode 257 images are loaded using an adaptive palette making these images look better than mode 256 when used with 32-bit color screens.
- 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.
Availability
- The capability to load from memory was introduced in QB64-PE v3.6.0.
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") 'use any 24/32 bit image 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$ > "" |
More examples
See also
- _FREEIMAGE, _ICON
- _PUTIMAGE, _MAPTRIANGLE
- _NEWIMAGE, _COPYIMAGE
- _PRINTIMAGE (printer)
- _PALETTECOLOR (function), _COPYPALETTE, _ICON
- SCREEN
- Hardware images
- Bitmaps, Icons and Cursors, GIF Images