PIXELSIZE: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 31: Line 31:
{{Cb|END FUNCTION}}
{{Cb|END FUNCTION}}
{{TextEnd}}
{{TextEnd}}
{{small|Adapted from code by Galleon}}
{{Small|Adapted from code by Galleon}}


=== More examples ===
=== More examples ===
* [[SAVEIMAGE]]
* [[SaveImage SUB]]
* [[SaveIcon32]]
* [[SaveIcon32]]
* [[ThirtyTwoBit SUB]]
* [[ThirtyTwoBit SUB]]
Line 41: Line 41:


{{PageSeeAlso}}
{{PageSeeAlso}}
* [[_LOADIMAGE]]
* [https://qb64phoenix.com/forum/showthread.php?tid=1362 Featured in our "Keyword of the Day" series]
* [[_NEWIMAGE]]
* [[_LOADIMAGE]], [[_SAVEIMAGE]]
* [[_PUTIMAGE]]
* [[_NEWIMAGE]], [[_PUTIMAGE]]
* [[_COPYPALETTE]]
* [[_COPYPALETTE]]




{{PageNavigation}}
{{PageNavigation}}

Latest revision as of 22:25, 25 May 2024

The _PIXELSIZE function returns the color depth (Bits Per Pixel) of an image as 0 for text, 1 for 1 to 8 BPP or 4 for 32 bit.


Syntax

pixelSize% = _PIXELSIZE[(imageHandle&)]


Description

  • If imageHandle& is omitted, it is assumed to be the current write page.
  • Returns:
    • 0 if the image or screen page specified by imageHandle& is in text mode.
    • 1 if the image specified by imageHandle& is in 1 (B & W), 4 (16 colors) or 8 (256 colors) BPP mode.
    • 4 if the image specified is a 24/32-bit compatible mode. Pixels use three bytes, one per red, green and blue color intensity.
  • The SCREEN or _NEWIMAGE or _LOADIMAGE color mode (256 or 32) can influence the pixel sizes that can be returned.
  • If imageHandle& is an invalid handle, then an invalid handle error occurs.


Examples

Snippet: Saving Images for later program use. Handle values could be saved to an array.


handle1& = _Getimage(sx1, sy1, sx2, sy2, sourcehandle&) ' function call

FUNCTION GetImage& (sx1, sy1, sx2, sy2, sourcehandle&)
bytespp = _PIXELSIZE(sourcehandle&)
IF bytespp = 4 THEN Pal = 32 ELSE IF bytespp = 1 THEN Pal = 256 ELSE EXIT FUNCTION
h& = _NEWIMAGE(ABS(sx2 - sx1) + 1, ABS(sy2 - sy1) + 1, Pal)
_PUTIMAGE (0, 0), sourcehandle&, h&, (sx1, sy1)-(sx2, sy2) 'image is not displayed
GetImage& = h&
END FUNCTION
Adapted from code by Galleon

More examples


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link