Reads alpha channel from locked image (requires b2dLockImage first, fast CPU buffer access, 0-255).
Takes imageHandle (locked image handle, positive integer, must have isLocked=true), x (horizontal pixel coordinate, integer, 0=left edge), y (vertical pixel coordinate, integer, 0=top edge).
Returns alpha channel value (0-255 integer, 0=fully transparent, 255=fully opaque), returns 0 on error (not locked, invalid handle, or out-of-bounds coordinates).
2D Overlay
Parameters & Returns
Parameters
imageHandleInt
xInt
yInt
Returns
Int
Quick Summary
Reads alpha channel from locked image (requires b2dLockImage first, fast CPU buffer access, 0-255).
Takes imageHandle (locked image handle, positive integer, must have isLocked=true), x (horizontal pixel coordinate, integer, 0=left edge), y (vertical pixel coordinate, integer, 0=top edge).
Returns alpha channel value (0-255 integer, 0=fully transparent, 255=fully opaque), returns 0 on error (not locked, invalid handle, or out-of-bounds coordinates).
Technical Exegesis...
Reads alpha channel from locked image (requires b2dLockImage first, fast CPU buffer access, 0-255). Takes imageHandle (locked image handle, positive integer, must have isLocked=true), x (horizontal pixel coordinate, integer, 0=left edge), y (vertical pixel coordinate, integer, 0=top edge). Returns alpha channel value (0-255 integer, 0=fully transparent, 255=fully opaque), returns 0 on error (not locked, invalid handle, or out-of-bounds coordinates). Reads from CPU buffer (img.
Reads alpha channel from locked image (requires b2dLockImage first, fast CPU buffer access, 0-255). Takes imageHandle (locked image handle, positive integer, must have isLocked=true), x (horizontal pixel coordinate, integer, 0=left edge), y (vertical pixel coordinate, integer, 0=top edge). Returns alpha channel value (0-255 integer, 0=fully transparent, 255=fully opaque), returns 0 on error (not locked, invalid handle, or out-of-bounds coordinates). Reads from CPU buffer (img.cpuPixelBuffer, direct memory access), calculates pixel index (index = (yxwidth+x)x4 row-major RGBA layout), returns A byte (buffer[index+3] alpha channel at offset 3). Use to detect transparency (check if pixel visible), implement pixel-perfect collision (check alpha at overlap points), create masks (extract alpha channel for masking), or analyze image data (opacity statistics, edge detection via alpha). Lock requirement: MUST call b2dLockImage first (downloads texture to CPU buffer, enables pixel access), fast access (direct CPU memory read, no GPU overhead per pixel), many reads efficient (one lock enables many GetPixel calls without GPU round-trips). Use cases: (1) Pixel-perfect collision (b2dLockImage(img1): b2dLockImage(img2): For overlap: If b2dGetPixelA(img1,x,y)>0 And b2dGetPixelA(img2,x,y)>0 Then collide), (2) Find opaque pixels (For y=0 To h: For x=0 To w: If b2dGetPixelA(img,x,y)=255 Then fully opaque), (3) Alpha mask extraction (For each pixel: mask[x,y]=b2dGetPixelA(img,x,y) extract transparency), (4) Bounding box calculation (scan for alpha>0 to find non-transparent region bounds), (5) Transparency statistics (count=0: For each pixel: If b2dGetPixelA(img,x,y)>128 Then count++ count semi-opaque pixels). Common patterns: check visible = If b2dGetPixelA(img,x,y)>0 Then pixel exists; full RGBA = r=b2dGetPixelR: g=b2dGetPixelG: b=b2dGetPixelB: a=b2dGetPixelA complete color. RGBA format: R at offset+0 (red channel), G at offset+1 (green channel), B at offset+2 (blue channel), A at offset+3 (alpha channel fourth byte), 4 bytes per pixel (RGBA tightly packed). Alpha values: 0=fully transparent (invisible, color ignored in rendering), 255=fully opaque (solid, no transparency), 1-254=semi-transparent (partial visibility, alpha blending), typical thresholds (>0 visible, >128 mostly opaque, =255 solid). Coordinate system: origin top-left (0,0 = top-left corner), x rightward (0=left edge, width-1=right edge), y downward (0=top edge, height-1=bottom edge), row-major layout (left-to-right, top-to-bottom). Index calculation: pixel index = (y x width + x) x 4 (offset to pixel's first byte), A byte = buffer[index+3] (add 3 for alpha channel), bounds check (x in 0 to width-1, y in 0 to height-1), out-of-bounds returns 0 (silently returns 0 for invalid coordinates, 0=transparent matches error semantic). Performance: access cost zero (direct CPU memory read, single array index), no GPU overhead (reads from CPU buffer, no GPU round-trips), amortized lock cost (one lock enables many reads), efficient for batch operations (collision checks, masking faster than GPU per-pixel). Validation: prints error if not locked (img.isLocked=false or cpuPixelBuffer=nullptr, returns 0), returns 0 if invalid handle (imageHandle not in g_images map), returns 0 if out-of-bounds (x<0 or x>=width or y<0 or y>=height), no coordinate adjustment (only validates, doesn't clamp). Related: b2dGetPixelR reads red channel (same usage, offset+0), b2dGetPixelG reads green channel (same usage, offset+1), b2dGetPixelB reads blue channel (same usage, offset+2), b2dLockImage enables access (required before this function), b2dUnlockImage completes cycle (required after done reading), b2dSetPixel writes pixel (modifies RGBA including alpha).