View Full Version : Checking a bitmap's alpha value
TheGrak 03-19-2011, 06:36 AM 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! :)
|
|
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.
Panayot
03-19-2011, 01:39 PM
If the case is just to test wheter the bitmap has alpha then this will save your time:
<bitmap>.hasAlpha
TheGrak
03-19-2011, 08:52 PM
@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)
)
)
CGTalk Moderation
03-19-2011, 08:52 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.