Notifications
Clear all

[Closed] Checking a bitmap's alpha value

I want to loop thru a bitmap’s values until I come across the first instance of a non 0 alpha value.
How would I go about doing this, say for example in this context:

local myPSDlayer = bitmapLayerManager.LoadLayer aPSDfile 1 true

Something like:

for thePixels in myPSDlayer.pixelData do 
   	if thePixel.value != 0 then print "value>0"

Thanks!

3 Replies
 lo1

you need to iterate over the pixels row by row using getpixels method. Get a row each time then iterate over each pixel of that row and check its .alpha property.

If the case is just to test wheter the bitmap has alpha then this will save your time:

<bitmap>.[b]hasAlpha[/b]

@Lo – thanks! thats what i needed.
@Panayot – i have to check each pixels value, but that’s a handy code snippet.

  Here is what I ended up using:
--iterate over the pixels row by row using getpixels method. 
 for g = 0 to myBitmapHeight by 1 do --for the height of the bitmap
 (
      	local myPixelRow = getPixels myFullframebitmap [0,g] myBitmapWidth --get a row of pixels	
      	for j = 1 to myPixelRow.count do --for every row of pixels
      	(
      		if myPixelRow[j] != (color 0 0 0 0) then --if the pixel isn't completely transparent
      		(format "Opaque found at: [%,%]" g j)
      	 )
 )