-
October 5th, 2005, 11:54 PM
#1
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
-
October 6th, 2005, 02:31 AM
#2
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
-
October 6th, 2005, 02:57 AM
#3
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
|