CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: text on bitmap

  1. #1
    Join Date
    Nov 2003
    Posts
    47

    text on bitmap

    Plz help me

    is there any programme in VB in which we can write a text On bitmap

    waiting for reply

    Faiza
    faiza

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: text on bitmap

    Hi!
    If your bitmap is loaded into a picture box, you can try this:
    You will need 4 command buttons,
    a text box (that contains your label)
    a picture box.

    Command button 1 will put a label on the bottom of the picture in several different styles depending on what you specify for the Draw Type (last parameter).

    Command button 2 will draw a standard label on a picture.
    Command button 3 demonstrates how to print the picture and label.
    Command button 4 demonstrates how to save the picture and label.
    The text box is used to specify the required picture label, altering the appearance of the text box will change the behaviour of the draw mode.

    Note :- for this to work correctly the form and PictureBox must have their Scalemode property set to Pixels and the PictureBox AutoRedraw property must be set to true.

    Paste this code into the form.

    Code:
    Private Sub Command1_Click()
    Picture1 = LoadPicture("location of.bmp") 
    LabelMyPicture Picture1.hdc, Picture1.Height, Picture1.Width, _
    Text1.hwnd, Text1.Height, Text1.Width, Solid
    End Sub
    
    Private Sub Command2_Click()
    Picture1 = LoadPicture("location of.bmp") 
    StandardLabel Picture1.hdc, Picture1.Height, Text1.Text
    End Sub
    
    Private Sub Command3_Click()
    Printer.PaintPicture Picture1.Image, 0, 0
    Printer.EndDoc
    End Sub
    
    Private Sub Command4_Click()
    SavePicture Picture1.Image, "c:\test.bmp"
    End Sub
    Paste this code into the module.

    Code:
    Private Type RECT
       Left As Long
       Top As Long
       Right As Long
       Bottom As Long
    End Type
    
    Private Type BITMAP
       bmType As Long
       bmWidth As Long
       bmHeight As Long
       bmWidthBytes As Long
       bmPlanes As Integer
       bmBitsPixel As Integer
       bmBits As Long
    End Type
    
    Public Enum DrawTypes
       Solid
       Inverse
       Alpha
       Delete
       Paint
    End Enum
    
    Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, _
    ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, _
    ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
    Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, _
    ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
    
    Public Sub LabelMyPicture(PicHDC As Long, PicHeight As Long, PicWidth As Long, TextBoxHwnd As Long, _
    TBHeight As Long, TBWidth As Long, DT As DrawTypes)
    ' Subroutine to label a picture in a picture box (Bottom, full width, backed label)
    '
    ' Call with :-
    '
    ' LabelMyPicture Picture1.hdc, Picture1.Height, Picture1.Width, _
    ' Text1.hwnd, Text1.Height, Text1.Width, Solid
    '
    ' Where Picture1 is a picture box containing the bitmap
    ' and
    ' Text1 is a textbox containing the picture label.
    '
    ' The final parameter is a draw style enumerator - experiment with these to see which looks best for you,
    ' changing the colours of the text box will alter the affect. Your text box should have no border and
    ' have the Appearance property set to flat.
    '
    Dim OutRect As RECT
    Dim InHdc As Long
    Dim rc As Long
    GetClientRect TextBoxHwnd, OutRect ' Get Dest text proportions
    InHdc = GetWindowDC(TextBoxHwnd)   ' Get Dest HDC
    If DT = Alpha Then
       rc = StretchBlt(PicHDC, 0, (PicHeight - TBHeight), PicWidth, TBHeight, InHdc, 0, 0, TBWidth, TBHeight, vbSrcAnd)
    ElseIf DT = Delete Then
       rc = StretchBlt(PicHDC, 0, (PicHeight - TBHeight), PicWidth, TBHeight, InHdc, 0, 0, TBWidth, TBHeight, vbSrcErase)
    ElseIf DT = Inverse Then
       rc = StretchBlt(PicHDC, 0, (PicHeight - TBHeight), PicWidth, TBHeight, InHdc, 0, 0, TBWidth, TBHeight, vbSrcInvert)
    ElseIf DT = Solid Then
       rc = StretchBlt(PicHDC, 0, (PicHeight - TBHeight), PicWidth, TBHeight, InHdc, 0, 0, TBWidth, TBHeight, vbSrcCopy)
    ElseIf DT = Paint Then
       rc = StretchBlt(PicHDC, 0, (PicHeight - TBHeight), PicWidth, TBHeight, InHdc, 0, 0, TBWidth, TBHeight, vbSrcPaint)
    End If
    End Sub
    
    Public Sub StandardLabel(PicHDC As Long, PicHeight As Long, OPStr As String)
    ' Subroutine to label a picture in a picture box (Bottom, left, unbacked label)
    '
    ' Call with :-
    '
    ' StandardLabel Picture1.hdc, Picture1.Height, Text1.Text
    '
    ' Where Picture1 is a picture box containing the bitmap
    ' and
    ' Text1 is a textbox containing the picture label.
    '
    Dim OutRect As RECT
    Dim InHdc As Long
    Dim rc As Long
    GetClientRect TextBoxHwnd, OutRect ' Get Dest text dimensions
    InHdc = GetWindowDC(TextBoxHwnd)   ' Get Dest HDC
    rc = TextOut(PicHDC, 0, (PicHeight - 18), OPStr, Len(OPStr))
    End Sub

  3. #3
    Join Date
    Sep 2005
    Location
    Delhi, INDIA
    Posts
    237

    Re: text on bitmap

    Hi Faiza,

    as i already emailed you the solution as you asked me earlier.. !

    I also explain here :

    see the attached file also !

    Code:
     
    Private Sub Command1_Click()
    	Picture1.CurrentX = 200		 'you can set the location in x axise
    	Picture1.CurrentY = 300		 'you can set the location in y axise
    	Picture1.ForeColor = vbRed	 'you can set the Fore Color
    	Picture1.Font.Size = 18		 'you can set the Size of the Text
    	Picture1.Font.Bold = True	 'you can set the Format
    	Picture1.Print "Hello Faiza"	'you can Print the Text also !!
    End Sub
    Hope u got it.. there is just 5-6 lines to do all. !

    Regards!
    Attached Files Attached Files
    I'M BACK AGAIN !!
    -------------------------------------------------------------------------
    enjoy the VB !
    If any post helps you, please rate that.
    Always try to findout the Solutions, instead just discussing the problem and its scope!

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

Featured