Is there an easy way to take a color image and convert it to a
grayscale image? Or even better, to take an OpaqueImage, and convert it to an OpaqueImageWithEnablement with the disabled figure the grayscale version of the enabled figure? Thanks, Mike |
On Apr 27, 2007, at 21:17, Mike Hales wrote:
How 'bout this? OpaqueImage>>withEnablement: anEnablement | gray | gray := CachedImage on: (Image extent: figure asImage extent depth: 1 bitsPerPixel: 1 palette: (MappedPalette with: SymbolicPaint inactiveForeground asColorValue)). ^(OpaqueImageWithEnablement figure: figure shape: shape inactiveFigure: gray inactiveShape: shape) isEnabled: anEnablement To test/play with it, I inspected: (ListIconLibrary visualFor: #class) withEnablement: [InputState default shiftDown] Then I could just refresh the inspector, if I hold the shift key, I see the normal, otherwise, I see the grayscale. Is that what you were looking for? -- Travis Griggs Objologist "Only one thing is impossible for God: to find any sense in any copyright law on the planet." - Mark Twain |
In reply to this post by Mike Hales
On Apr 27, 2007, at 21:17, Mike Hales wrote:
Or perhaps, on reflection (pun?), you really meant grayscale when you said grayscale. :) Here's a version that does that. The exact algorithm to use in the paintTransfer block is yours to derive. You could use brightness, saturation, luminance, etc. I found 1 - saturation to be appealing for that particular icon. Luminance a second. Please note that if your original figure is a 32bpp Image and has nonzero values in the X byte (i.e. you grabbed it from a Screen capture of a desktop that does transparency like the Mac), you will have issues with the convert. Load FixedPaletteFixed from the OR to get around it. OpaqueImage>>prettyEnablement: anEnablement | gray | gray := CachedImage on: (figure asImage convertToPalette: (MappedPalette withColors: ((0 to: 255) collect: [:n | ColorValue brightness: n / 255])) renderedBy: NearestPaint new paintTransfer: [:color | ColorValue brightness: 1 - color saturation]). ^(OpaqueImageWithEnablement figure: figure shape: shape inactiveFigure: gray inactiveShape: shape) isEnabled: anEnablement -- Travis Griggs Objologist "You A students, you'll be back soon teaching here with me. You B students, you'll actually go on to be real engineers. You C students, you'll go into management and tell the A and B students what to do." - My Fluid Dynamics Professor whom I have yet to disprove |
Perfect! Thanks at ton. I'll see you on Monday.
Mike On Apr 28, 2007, at 4:36 AM, Travis Griggs wrote:
|
Free forum by Nabble | Edit this page |