zoukankan      html  css  js  c++  java
  • DrawString动态填写图片单据

    Imports System.Drawing
    Imports System.Drawing.Imaging

     
    '生成银行电汇单据
        Private Sub CreateBankBill()
            
    Dim imgBill As System.Drawing.Image
            
    Dim imgPath As String = Server.MapPath("../images/PayeeBank.jpg")
            imgBill 
    = Image.FromFile(imgPath)

            
    Dim fontR As New Font("Courier New"8)
            
    Dim fontW As New Font("Verdana"8)
            
    Dim colorR As System.Drawing.Color = Color.Red
            
    Dim colorW As System.Drawing.Color = Color.Black

            
    Dim IER As Double = 28.35 '[Cm] * IER ≈ [Pixel]
            Dim yDEC As Double = 0.5 '文字行间距(含字高cm)
            Dim strReceiverFullName As String = "南京易点网络软件有限公司"  '右上-收款人全称
            Dim pFullName As System.Drawing.PointF = New PointF(IER * 10.4, IER * 2'p(x[28.35*10.4],y[28.35*2])
            Dim strReceiverAccountsOrAddr As String = "123456789" '右上-收款人帐号或地址
            Dim pAccoAddr As System.Drawing.PointF = New PointF(IER * 10.4, IER * 2.8)
            
    Dim strProvince As String = "江苏" '右-收款人省份
            Dim pProvince As System.Drawing.PointF = New PointF(IER * 10.4, IER * 4.3)
            
    Dim strCity As String = "南京" '右-收款人城市
            Dim pCity As System.Drawing.PointF = New PointF(IER * 11.8, IER * 4.3)

            
    Dim strBank As String = "华夏银行白下支行银联" '右-汇入行名称
            'Dim pBank As System.Drawing.PointF = New PointF(IER * 14.4, IER * 3.8)       
            Dim RowCount As Integer = Math.Ceiling(strBank.Length / 4)
            RowCount 
    = RowCount - 1
            
    Dim arrBank(,)
            
    ReDim arrBank(RowCount, 1)
            
    Dim i As Integer
            
    For i = 0 To UBound(arrBank, 1)
                
    Dim str As String
                
    If i < UBound(arrBank, 1Then
                    
    str = strBank.Substring(i * 44)
                
    Else
                    
    str = strBank.Substring(i * 4)
                
    End If
                
    Dim p As System.Drawing.PointF = New PointF(IER * 14.4, IER * (3.8 + i * yDEC))
                arrBank(i, 
    0= str
                arrBank(i, 
    1= p
            
    Next

            
    Dim arr(,) As String = {{"用 户 名""BlueKnight"}, {"产品类型""EasySales"}, {"购买期限""3个月"}, {"联系电话""025-12349484"}}

            
    Dim arrPurpose(,)
            
    ReDim arrPurpose(UBound(arr, 1), 3)
            
    For i = 0 To UBound(arrPurpose, 1)
                arrPurpose(i, 
    0= CStr(i + 1& "" & CStr(arr(i, 0))
                arrPurpose(i, 
    1= New PointF(IER * 3.8, IER * (7 + i * yDEC))
                arrPurpose(i, 
    2= arr(i, 1)
                arrPurpose(i, 
    3= New PointF(IER * 6.4, IER * (7 + i * yDEC))
            
    Next


            
    Dim b As Bitmap = New Bitmap(imgBill.Width, imgBill.Height, PixelFormat.Format24bppRgb)
            
    Dim g As Graphics = Graphics.FromImage(b)
            g.Clear(Color.White)
            
    ' FONT-FAMILY: Verdana, Webdings

            g.DrawImage(imgBill, 
    New Point(00))
            g.DrawString(strReceiverFullName, fontR, 
    New SolidBrush(colorR), pFullName)
            g.DrawString(strReceiverAccountsOrAddr, fontR, 
    New SolidBrush(colorR), pAccoAddr)
            g.DrawString(strProvince, fontR, 
    New SolidBrush(colorR), pProvince)
            g.DrawString(strCity, fontR, 
    New SolidBrush(colorR), pCity)

            
    For i = 0 To UBound(arrBank, 1)
                g.DrawString(
    CType(arrBank(i, 0), String), fontR, New SolidBrush(colorR), CType(arrBank(i, 1), PointF))
            
    Next
            
    For i = 0 To UBound(arrPurpose, 1)
                g.DrawString(
    CStr(arrPurpose(i, 0)), fontR, New SolidBrush(colorR), CType(arrPurpose(i, 1), PointF))
                g.DrawString(
    CStr(arrPurpose(i, 2)), fontW, New SolidBrush(colorW), CType(arrPurpose(i, 3), PointF))
            
    Next


            Response.ContentType 
    = "image/jpeg"
            b.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
            b.Dispose()
        
    End Sub


        
    '生成邮政汇款单
        Private Sub CreatePostBill()
            
    Dim imgBill As System.Drawing.Image
            
    Dim imgPath As String = Server.MapPath("../images/PayeePost.jpg")
            imgBill 
    = Image.FromFile(imgPath)

            
    Dim fontW As New Font("Courier New"8)
            
    Dim colorW As System.Drawing.Color = Color.Black

            
    Dim IER As Double = 28.35 '[Cm] * IER ≈ [Pixel]
            Dim xDEC As Double = 0.72 '文字列间距(含字宽cm)
            Dim yDEC As Double = 0.5 '文字行间距(含字高cm)
            Dim yDEC2 As Double = 0.85 '附言文字行间距(含字高cm)
            Dim strPostCode As String = "210005"    '//邮编
            Dim arrPostCode(,)
            
    ReDim arrPostCode(strPostCode.Length - 11)
            
    Dim i As Integer
            
    For i = 0 To strPostCode.Length - 1
                arrPostCode(i, 
    0= strPostCode.Chars(i)
                arrPostCode(i, 
    1= New System.Drawing.PointF((1.84 + i * xDEC) * IER, 1.14 * IER)
            
    Next
            
    Dim strName As String = "南京易点网络软件有限公司" '//收款人姓名
            Dim RowCount As Integer = Math.Ceiling(strName.Length / 7)
            RowCount 
    = RowCount - 1
            
    Dim arrName(,)
            
    ReDim arrName(RowCount, 1)
            
    For i = 0 To UBound(arrName, 1)
                
    Dim str As String
                
    If i < UBound(arrName, 1Then
                    
    str = strName.Substring(i * 77)
                
    Else
                    
    str = strName.Substring(i * 7)
                
    End If
                
    Dim p As System.Drawing.PointF = New PointF(3.3 * IER, (3.8 - i * yDEC) * IER)
                arrName(i, 
    0= str
                arrName(
    UBound(arrName, 1- i, 1= p
            
    Next
            
    Dim strAddr As String = "江苏省南京市白下区新街口华联商厦14楼1411室" '//收款人地址
            Dim pAddr As System.Drawing.PointF = New PointF(4.6 * IER, 4.6 * IER)

            
    Dim arrPostScript As New ArrayList           '//附言
            arrPostScript.Add("★ 请务必在附言栏中详细填写以下内容")
            arrPostScript.Add(
    "用 户 名" & ControlChars.Tab & "BlueKnight")
            arrPostScript.Add(
    "产品类型" & ControlChars.Tab & "EasyInsurance")
            arrPostScript.Add(
    "购买期限" & ControlChars.Tab & "3个月")
            arrPostScript.Add(
    "您的联系电话" & ControlChars.Tab & "13855512065")
            
    Dim arrPS(,)
            
    ReDim arrPS(arrPostScript.Count - 11)
            
    For i = 0 To UBound(arrPS, 1)
                arrPS(i, 
    0= IIf(i > 0CStr(i) & """"& CStr(arrPostScript.Item(i))
                arrPS(i, 
    1= New PointF(IER * 3, IER * (19.6 + i * yDEC2))
            
    Next


            
    Dim b As Bitmap = New Bitmap(imgBill.Width, imgBill.Height, PixelFormat.Format24bppRgb)
            
    Dim g As Graphics = Graphics.FromImage(b)
            g.Clear(Color.White)

            g.DrawImage(imgBill, 
    New Point(00))
            
    'g.DrawString(str, fontStr, New SolidBrush(colorStr), p)
            For i = 0 To UBound(arrPostCode, 1)
                g.DrawString(
    CStr(arrPostCode(i, 0)), fontW, New SolidBrush(colorW), CType(arrPostCode(i, 1), PointF))
            
    Next
            
    For i = 0 To UBound(arrName, 1)
                g.DrawString(
    CStr(arrName(i, 0)), fontW, New SolidBrush(colorW), CType(arrName(i, 1), PointF))
            
    Next
            g.DrawString(strAddr, fontW, 
    New SolidBrush(colorW), pAddr)
            
    For i = 0 To UBound(arrPS, 1)
                g.DrawString(
    CStr(arrPS(i, 0)), fontW, New SolidBrush(colorW), CType(arrPS(i, 1), PointF))
            
    Next

            Response.ContentType 
    = "image/jpeg"
            b.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
            b.Dispose()
        
    End Sub
  • 相关阅读:
    shop--6.店铺注册--service层实现(事务)
    shop--6.店铺注册--Dto的ShopExection(不知道有什么用)
    shop--6.店铺注册--使用thumbnailator进行图片处理
    shop--6.店铺注册
    shop--0.项目中遇到的问题 插入数据时,直接拿到自增的Id的方法
    shop--5.使用Junit进行项目框架的验证
    shop--4.配置数据库连接 jdbc.properties,mybatis相关,Spring配置
    shop--3.配置maven
    codeforces 495B. Modular Equations 解题报告
    BestCoder22 1002.NPY and arithmetic progression(hdu 5143) 解题报告
  • 原文地址:https://www.cnblogs.com/ding0910/p/369455.html
Copyright © 2011-2022 走看看