Hey all,
I'm working on a pdf embellishment app and am having problems with drawing performance.

I convert pdf files to images and the image size is rather large (5000x3000). I could solve my problem by reducing the image size, but that is not an option (o how I wish it was) so I have to deal with big images.

The gist of the app is to draw the pdf image on a control, then draw an overlay image on the control after drawing the pdf image. The overlay image is the exact same size as the pdf image so I can handle panning and zooming fairly easily.

My issue is when I draw a highlight block (bright yellow over text to highlight... you know). The first obvious way to do this was to draw a simple rectangle using color.yellow with the alpha value set to make the block semi-transparent. This looks bad though. The yellow block looks faded and the text under it also looks faded.

What I have resorted to is copy the part of the pdf image that the block covers and change the white pixels to yellow. Since the pdf image is guaranteed to be black text on a white background, this works exceptionally well... the text remains black, and the highlight is nice and bright. Unfortunately it takes a while to make this white to yellow conversion and given the size of the images I'm dealing with, the problem gets exponentially worse as the highlight block size increases.

Here is my code for the conversion...
VB.net Code:
  1. Private Sub drawHighlight(gr As Graphics, r As Rectangle)
  2.  
  3.         'r is the highlight block rectangle
  4.         If r.Width > 0 AndAlso r.Height > 0 Then
  5.             'create a new image using the block size
  6.             Using img As New Bitmap(r.Width, r.Height)
  7.  
  8.                 RaiseEvent GetHighlightedImage(r, img) '<---this gets the underlying pdf image; img is passed ByRef
  9.                 'iterate the image's pixels
  10.                 For x As Integer = 0 To img.Width - 1
  11.                     For y As Integer = 0 To img.Height - 1
  12.                         'get the color of the pixel
  13.                         Dim c As Color = img.GetPixel(x, y)
  14.  
  15.                         'if the R,G & B are larger than the threshold, then change the pixel to yellow
  16.                         Const BW_THREASHOLD As Integer = 200
  17.                         If c.R > BW_THREASHOLD AndAlso c.G > BW_THREASHOLD AndAlso c.B > BW_THREASHOLD Then
  18.                             img.SetPixel(x, y, Me.BackColor)
  19.                         End If
  20.                     Next
  21.                 Next
  22.                 'finally draw the image on the overlay
  23.                 gr.DrawImage(img, r.Location)
  24.             End Using
  25.         End If
  26.     End Sub
So is there a way that I can increase performance of this routine (significantly)?

Thanks for looking... Cheers!
kevin