|
-
Feb 23rd, 2017, 10:42 AM
#1
[RESOLVED] draw highlights over an image
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:
Private Sub drawHighlight(gr As Graphics, r As Rectangle)
'r is the highlight block rectangle
If r.Width > 0 AndAlso r.Height > 0 Then
'create a new image using the block size
Using img As New Bitmap(r.Width, r.Height)
RaiseEvent GetHighlightedImage(r, img) '<---this gets the underlying pdf image; img is passed ByRef
'iterate the image's pixels
For x As Integer = 0 To img.Width - 1
For y As Integer = 0 To img.Height - 1
'get the color of the pixel
Dim c As Color = img.GetPixel(x, y)
'if the R,G & B are larger than the threshold, then change the pixel to yellow
Const BW_THREASHOLD As Integer = 200
If c.R > BW_THREASHOLD AndAlso c.G > BW_THREASHOLD AndAlso c.B > BW_THREASHOLD Then
img.SetPixel(x, y, Me.BackColor)
End If
Next
Next
'finally draw the image on the overlay
gr.DrawImage(img, r.Location)
End Using
End If
End Sub
So is there a way that I can increase performance of this routine (significantly)?
Thanks for looking... Cheers!
kevin
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|