怎样在图片框中的特定位置print竖直文本,该如何解决
怎样在图片框中的特定位置print竖直文本
如题
------解决方案--------------------
使用GDI+来绘制是最佳的选择
------解决方案--------------------
如题
------解决方案--------------------
使用GDI+来绘制是最佳的选择
------解决方案--------------------
- VB code
'1、本例使用Gdiplus.tlb来实现GDI+编程,使用前请先现在一个Gdiplus.tlb '2、使用Gdiplus.tlb,将其放到system32中,然后添加对其的引用 '3、手动设置Form的AutoRedraw=True,ScaleMode=Pixels Option Explicit Dim lngGraphics As Long Dim gpP As GpStatus Dim lngPen1 As Long Dim lngToken As Long Dim lngSolidBrush As Long Dim GpInput As GdiplusStartupInput Private lngFontFamily As Long '字体类型 Private lngStringFormat As Long '字符串格式 Private Sub Command1_Click() Dim intP As Integer Dim bolP As Boolean gpP = GdipCreateFromHDC(Me.hDC, lngGraphics) gpP = GdipCreatePen1(&H80FF0000, 2, UnitPixel, lngPen1) bolP = DrawNormalText("新宋体", &H808000FF, StringAlignmentNear, _ 30, FontStyle.FontStyleBold, UnitPixel, _ TextRenderingHintAntiAliasGridFit, 2, 100, 450, 128, _ "**人民*") bolP = DrawSpecialText("Verdana", &HFFFFFFFF, StringAlignmentNear, _ FontStyle.FontStyleBold, &HFF00FF00, 1.2, _ UnitPixel, FillModeAlternate, 40, 460, 100, 240, 128, "ABCD123", 0) Me.Refresh End Sub Private Sub Form_Load() Dim bolP As Boolean With Me .Caption = "GDIPlus范例" .Width = 960 * 15 .Height = 720 * 15 .Left = (Screen.Width - .Width) * 0.5 .Top = (Screen.Height - .Height) * 0.5 End With GpInput.GdiplusVersion = 1 If lngToken = 0 Then bolP = (GdiplusStartup(lngToken, GpInput) = Ok) End Sub '************************************************************************************************************************ '函数功能:按照一定的格式书写文字,正常排列(不包括:旋转、描边等) '参数说明:strFontName:字体名称 ' :lngFontColor:文字颜色 ' :stringAlignMode:对齐方式 ' :sngFontSize:字体大小 ' :lngFontStyle:字体样式(粗体、斜体..) ' :DrawUnit:绘图单元 ' :TextRenderMode:文本渲染模式 ' :lngLeft:绘制文本区域 Left ' :lngTop:绘制文本区域 Top ' :lngWidth:绘制文本区域 Width ' :lngHeight:绘制文本区域 Height ' :strText:要书写的文本 '返回说明:成功:True 失败:False '************************************************************************************************************************ Private Function DrawNormalText(ByVal strFontName As String, ByVal lngFontColor As Long, _ ByVal StringAlignMode As StringAlignment, _ ByVal sngFontSize As Single, ByVal lngFontStyle As Long, _ ByVal DrawUnit As GpUnit, ByVal TextRenderMode As TextRenderingHint, _ ByVal lngLeft As Long, ByVal lngTop As Long, _ ByVal lngWidth As Long, ByVal lngHeight As Long, ByVal strText As String) As Boolean Dim gpP As GpStatus Dim lngCurFont As Long Dim rclayout As RECTF On Error GoTo errFun gpP = GdipCreateFontFamilyFromName(strFontName, 0, lngFontFamily) gpP = GdipCreateStringFormat(0, 0, lngStringFormat) gpP = GdipCreateSolidFill(lngFontColor, lngSolidBrush) gpP = GdipSetStringFormatAlign(lngStringFormat, StringAlignMode) gpP = GdipCreateFont(lngFontFamily, sngFontSize, lngFontStyle, DrawUnit, lngCurFont) gpP = GdipSetTextRenderingHint(lngGraphics, TextRenderMode) With rclayout .Left = lngLeft .Top = lngTop .Width = lngWidth .Height = lngHeight End With gpP = GdipDrawString(lngGraphics, strText, -1, lngCurFont, rclayout, lngStringFormat, lngSolidBrush) gpP = GdipDeleteFontFamily(lngFontFamily) gpP = GdipDeleteStringFormat(lngStringFormat) gpP = GdipDeleteFont(lngCurFont) gpP = GdipDeleteBrush(lngSolidBrush) lngSolidBrush = 0 lngFontFamily = 0 If IsNull(gpP) Then DrawNormalText = False Else DrawNormalText = True End If Exit Function errFun: DrawNormalText = False End Function '************************************************************************************************************************ '函数功能:按照一定的格式书写文字,特殊格式包括:旋转、描边等 '参数说明:strFontName:字体名称 ' :lngBrushColor:文字颜色 ' :stringAlignMode:对齐方式 ' :lngFontStyle:字体样式(粗体、斜体..) ' :lngLineColor:边框颜色 ' :sngLineWidth:边框宽度 ' :DrawLineUnit:边框绘制单位 ' :sngFontSize:字体大小 ' :lngLeft:绘制文本区域 Left ' :lngTop:绘制文本区域 Top ' :lngWidth:绘制文本区域 Width ' :lngHeight:绘制文本区域 Height ' :strText:要书写的文本 ' :dblAngle:字符串和X轴正方向的夹角(0~2*Pi) '返回说明:成功:True 失败:False '************************************************************************************************************************ Private Function DrawSpecialText(ByVal strFontName As String, ByVal lngBrushColor As Long, _ ByVal StringAlignMode As StringAlignment, ByVal lngFontStyle As Long, _ ByVal lngLineColor As Long, ByVal sngLineWidth As Single, _ ByVal DrawLineUnit As GpUnit, ByVal BrushMode As FillMode, _ ByVal sngFontSize As Single, ByVal lngLeft As Long, _ ByVal lngTop As Long, ByVal lngWidth As Long, _ ByVal lngHeight As Long, ByVal strText As String, _ ByVal dblAngle As Double) As Boolean Dim gpP As GpStatus Dim lngStringPath As Long Dim rclayout As RECTL On Error GoTo errFun gpP = GdipCreateFontFamilyFromName(strFontName, 0, lngFontFamily) '创建字体类型 gpP = GdipCreateStringFormat(0, 0, lngStringFormat) '创建字符串格式 gpP = GdipSetStringFormatAlign(lngStringFormat, StringAlignMode) '设置字符串格式 gpP = GdipCreateSolidFill(lngBrushColor, lngSolidBrush) '创建一个实心刷子 gpP = GdipCreatePen1(lngLineColor, sngLineWidth, DrawLineUnit, lngPen1) With rclayout .Left = lngLeft .Top = lngTop .Width = lngWidth .Height = lngHeight End With gpP = GdipCreatePath(BrushMode, lngStringPath) gpP = GdipAddPathStringI(lngStringPath, strText, -1, lngFontFamily, _ lngFontStyle, sngFontSize, rclayout, lngStringFormat) gpP = GdipFillPath(lngGraphics, lngSolidBrush, lngStringPath) gpP = GdipDrawPath(lngGraphics, lngPen1, lngStringPath) If IsNull(gpP) Then DrawSpecialText = False Else DrawSpecialText = True End If gpP = GdipDeleteFontFamily(lngFontFamily) gpP = GdipDeleteStringFormat(lngStringFormat) gpP = GdipDeletePath(lngStringPath) gpP = GdipDeleteBrush(lngSolidBrush) gpP = GdipDeletePen(lngPen1) lngSolidBrush = 0 lngFontFamily = 0 lngPen1 = 0 Exit Function errFun: DrawSpecialText = False End Function