Results 1 to 4 of 4

Thread: StretchBlt Blending

  1. #1

    Thread Starter
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    StretchBlt Blending

    Hello

    I'm StretchBlt'ing text (black text color, white background) onto an image. The image is a scanned copy of a hand-written form, with boxes for the different text fields I'm StretchBlt'ing in--I have to print the text inside these (blue outlined, almost white but non-solid fill color) boxes. (If you're curious, I'm using StretchBlt to horizontally squeeze the text as needed, to maximize use of space)

    The trouble is, to set the printed text offset properly, the bounding box of the text needs to be under the bottom line of most boxes. So whenever I StretchBlt, part of the bottom line of the text box gets overwritten with the almost-white fill color from the text.

    I've tried using the ScrAnd raster operation, but it only worked if I left the background picture unstretched (which I can't do).

    So, I was wondering if there was a way I could blend the source and destination colors (but not pixel-by-pixel, that would be WAYY too slow). If I could simply take the darker of the two colors, that would be fine. Any thoughts are appreciated.

    Thanks!
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  2. #2
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: StretchBlt Blending

    vb Code:
    1. Private Type RECT
    2. Left As Long
    3. Top As Long
    4. Right As Long
    5. Bottom As Long
    6. End Type
    7.  
    8. Private Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
    9. Private Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    10.  
    11. Private Const DT_LEFT = &H0
    12. Private Const DT_TOP = &H0
    13. Private Const DT_WORDBREAK = &H10
    14.  
    15. Private Sub DrawOnPictureBox(ByRef PictBox As PictureBox, ByVal TxtStr As String)
    16. Dim Rct As RECT
    17. PictBox.Cls
    18. SetRect Rct, 0, 0, PictBox.ScaleWidth, PictBox.ScaleHeight
    19. DrawText PictBox.hdc, TxtStr, Len(TxtStr), R, DT_LEFT Or DT_TOP Or DT_WORDBREAK
    20. End Sub
    21.  
    22. Private Sub Command1_Click()
    23. DrawOnPictureBox Picture1, Text1.Text
    24. End Sub

    This appeared to set the text in Text1 to the Picturebox. Is it something like that you want?

  3. #3

    Thread Starter
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    Re: StretchBlt Blending

    Thank you for your reply!

    Sorry, I *think* that that code is basically what's behind the built-in Print method of pictureboxes, printers, and forms.


    Basically, I have two images, and I'm copying one onto the other. What I want to do is blend them so that lighter colors on either image are overwritten by darker colors. The specifics are in my first post, but that's really what I want to do.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  4. #4
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: StretchBlt Blending

    Could you create an example, reflecting your problem? it's easier to see it in code, and we could work there.
    Maybe you don't even need StrechtBlt, maybe you can use PaintPicture, it also allows resizing and the Opcode parameter (vbSrcCopy, vbDstInvert, vbMergeCopy, vbSrcAnd, vbMergePaint ..etc), did you try all of these?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width