Programmatically determine the average greyscale
Sannyasin Brahmanathaswami
brahma at hindu.org
Fri Feb 19 00:29:35 EST 2016
Ha! I figured this out just before seeing this email..this is a match for Scott Rossi's method, which is right from the dictionary on ImageData
on mouseUp
put (39 * 4 * 205 ) into tRowsToSkip # takes us down the pixel map 39 rows
put tRowsToSkip + (39 *4) +2 into tRedTarget # now we are in the 40th pix for left red value
put tRowsToSkip + (39 *4) +3 into tGreenTarget
put tRowsToSkip + (39 *4) +4 into tBlueTarget
put charToNum(char tRedTarget of the imageData of image id 1110) into tRed
put charToNum (char tGreenTarget of the imageData of image id 1110) into tGreen
put charToNum(char tBlueTarget of the imageData of image id 1110) into tBlue
put (tRed &"," & tGreen &"," & tBlue)
end mouseUp
Svasti Astu! Be Well
Brahmanathaswami
www.himalayanacademy.com(http://www.himalayanacademy.com)
Get the Gurudeva.app here:
http://www.himalayanacademy.com/apps/gurudeva
On February 18, 2016 at 5:02:10 PM, J. Landman Gay (jacque at hyperactivesw.com(mailto:jacque at hyperactivesw.com)) wrote:
> On 2/18/2016 8:44 PM, Sannyasin Brahmanathaswami wrote:
> > Thanks that could be useful... BTW where to you store this kind of snippet
>
> In an old HC stack I made 20 years ago that I've converted to LC. It's
> not fit for public consumption but it has all my stuff in it so I keep
> using it.
>
> > how do you get the color a specific pixel in an image?
>
> I have three examples. The first one is mine, based on a suggestion from
> Scott Raney. The other two are more sophisticated because they use math...
>
> Jacque's:
>
> on getPixelColor pPt -- pass local stack-based pt
> put the screenmouseloc into tOldLoc
> put (item 1 of pPt) + (the left of this stack) into tloc
> put (item 2 of pPt) + (the top of this stack) into item 2 of tloc
> set the screenmouseloc to tloc
> put the mousecolor into tColor
> set the screenmouseloc to tOldLoc
> return tColor
> end getPixelColor
>
> It happens so fast you never see the cursor move.
>
> ------
>
> Unknown author:
>
> function readPixelColor pVal
> put globalLoc(pVal) into pVal
> put item 1 of pVal + 1 into item 3 of pVal
> put item 2 of pVal + 1 into item 4 of pVal
> export snapshot from rect pVal to templateImage
> get the imageData of templateImage
> reset templateImage
> return byteToNum(char 2 of it) & "," & byteToNum(char 3 of it) & ","
> & byteToNum(char 4 of it)
> end readPixelColor
>
> -------
> Scott Rossi:
>
> local theImageData
>
> function getPixelColor pImage,pX,pY
> if theImageData is empty then put the imageData of pImage into
> theImageData
> put width of pImage into W
> put ((pY-1)*W)*4+pX*4 into lastChar
> put charToNum(char lastChar of theImageData) into B
> put charToNum(char lastChar-1 of theImageData) into G
> put charToNum(char lastChar-2 of theImageData) into R
> return R,G,B
> end getPixelColor
>
>
> --
> Jacqueline Landman Gay | jacque at hyperactivesw.com
> HyperActive Software | http://www.hyperactivesw.com
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the use-livecode
mailing list