Programmatically determine the average greyscale

-hh hh at livecode.org
Sat Feb 20 09:56:52 EST 2016


> BR wrote:
> HH You are right of course. one pixel was an expediency and certainly
> does not cover all cases. In fact it is a rather weak algorithm ...
> ... Musings:
> A random algorithm also does not help us out either.  

BR,

[1] I didn't say a single random pixel is the way to go.
I simply accepted your single-pixel-way and tried to improve it.

[2] You CAN solve this in a very short time with LiveCode.

You could give the following a try (less than 5 minutes).
This is ONE 'static' setting, that works for ALL images.

Make a new textField, that will use contrast to *every* single pixel
that is below the text.
It requires later on only to script that the name of the buttons will
be hidden and instead displayed by the correspondingly placed and sized
field (you can use with that even formattedHeight and formattedWidth to
optimize sizing and location).

Settings:
opaque=false
locktext=true
autohilite=false
forecolor=255,255,255
script="on mouseDown;grab me;end mouseDown"

ink=notSrcOrReverse
showBorder=true -- needed with that ink or if you wish a border
borderWidth=0   -- needed with that ink, not if you wish a border

blending=12
Increase the blendlevel to have less contrast
between "black" (darkGrey) and "white" (lightGray)
blendLevel=0 gives 'full' black and white

Now bring this field to front and drag it over any part
of pictures or black/gray/white rectangles of your stack.
You should have readable contrast while dragging and
whereever you drag it (if the field is not empty).

I tried with your link that resolves to "skitch.png",
works as expected.

-hh

Below are the properties of my test field for looking up,
in case you use different default values.
=========================
altId=0
autoHilite=false
autoTab=false
backColor=0,0,0
backPattern=
behavior=
blendLevel=12
borderColor=
borderPattern=
borderWidth=0
bottomColor=
bottomPattern=
cantSelect=false
colorOverlay=
cursorMovement=default
disabled=false
dontSearch=false
dontWrap=false
dropShadow=
firstIndent=0
fixedLineHeight=true
focusColor=
focusPattern=
foreColor=255,255,255
forePattern=
hGrid=false
hScroll=0
hScrollbar=false
hiliteColor=
hilitePattern=
hilitedLines=
htmlText=<p>Knowledge</p>
id=1005
ink=notSrcOrReverse
innerGlow=
innerShadow=
layer=6
layerMode=static
listBehavior=false
lockLoc=false
lockText=true
margins=8
multipleHilites=false
name=Field
noncontiguousHilites=false
opaque=false
outerGlow=
rect=146,284,460,360
scrollbarWidth=20
shadow=false
shadowColor=
shadowOffset=4
shadowPattern=
sharedText=false
showBorder=true
showFocusBorder=true
showLines=false
style=transparent
tabStops=
textAlign=center
textDirection=auto
textFont=Arial Black
textHeight=
textSize=48
textStyle=plain
threeD=false
threeDHilite=false
toggleHilites=false
toolTip=
topColor=
topPattern=
traversalOn=true
vGrid=false
vScroll=0
vScrollbar=false
visible=true




More information about the use-livecode mailing list