views:

134

answers:

2

How can i create a realistic highlighter (simulating a real world highlighter pen) in .NET using GDI+? It is meant to be used on a graphics object not on selectable text.

Using a transparent brush (with alpha channel) doesn't do the job since everything below the area covered by the brush gets "fuzzy", and i would like the "foreground" (mostly text) to stay clear (keep it's color).

Using a ColorMap for only the background area could work but this would require a lot of code to determine the background area and a certain threshold (i could pick the background form the first pixel or top right pixel or something).

A ColorMatrix to colorize an area seems also an option but i see the same problem as the transparent brush solution (i am no expert on ColorMatrices so i might overlook something).

I guess i need a dynamic threshold for both the foreground and the background colors but this could reduce the usability of the highlighter.

I could live with both a solution that fills a "selected" area or a brush like solution.

A: 

I'm thinking that a brush of a given width and height that, as it's dragged across an area of the screen, grabs the section beneath it and analyzes it, setting non-text color to yellow and leaving text color alone, then placing the updated section back onto the screen. It should be relatively quick and easy to do this, though you do have to hit each pixel (and use some sort of threshold to determine what's text and what isn't, as you mentioned).

Michael Todd
+2  A: 

Here's an article that discusses how to do various blending operations in GDI+. Based on my experimentation, a Darken or Multiply blend mode would do the trick.

http://www.codeproject.com/KB/GDI-plus/KVImageProcess.aspx

Mark Ransom