用户名:
密 码:
验证码:





        
庆祝51Testing软件测试网成立五周年 [SilkTest] 关于SilkTest中的场景恢复函数
    [QTP]在图片上加标注
作者: 蓝天伟  文章类别: 蓝天测试  发表时间: 2009-7-20 12:52:12 阅读(471)

    最近在网上看到一些朋友在寻找关于在图片中加标注的脚本,关于这些脚本其实在07年就有人写出,主要是通过调用第三方工具ASPJPEG的COM来实现。以下是具体代码:
Function JPG_DrawEllipseAndStrin(filename,str,leftlen,toplen,rightlen,bottomlen)
'******************************
' Description:   Add note to a picture at specific area
' Precondition:  Install tool aspjpeg
' Input:         filename---Picture path
'                str--------String to write
'                leftlen----left lenth to original point
'                toplen-----top lenth to original point
'                rightlen---right lenth to original point
'                bottomlen-bottom lenth to original point
' Output:        None
' Example:       JPG_DrawEllipseAndString("C:\org.jpg","LantianWei",100,200,500,400)
' Tester:        LantianWei(wan1314sq@126.com
' Date:          Dec 23, 2007
'******************************
        Dim Jpeg,tmpleft,tmptop,tmpright,tmpbottom
        Set Jpeg=CreateObject("Persits.Jpeg")
        Jpeg.Open filename
        Jpeg.Canvas.Pen.Color=vbRed 
        Jpeg.Canvas.Pen.Width=2
        Jpeg.Canvas.Brush.Solid=False '是否加粗
        Jpeg.Canvas.Ellipse leftlen,toplen,rightlen,bottomlen '画椭圆
       
        If leftlen>Jpeg.OriginalWidth/2 Then
                tmpleft=leftlen
                tmptop=toplen+(bottomlen-toplen)/2
                If toplen+(bottomlen-toplen)/2>Jpeg.OriginalHeight/2 Then
                        tmpright=leftlen-100
                        tmpbottom=toplen+(bottomlen-toplen)/2-100
                Else
                        tmpright=leftlen-100
                        tmpbottom=toplen+(bottomlen-toplen)/2+100
                End If
        Else
                tmpleft=rightlen
                tmptop=toplen+(bottomlen-toplen)/2
                If toplen+(bottomlen-toplen)/2>Jpeg.OriginalHeight/2 Then
                        tmpright=rightlen+100
                        tmpbottom=toplen+(bottomlen-toplen)/2-100
                Else
                        tmpright=rightlen+100
                        tmpbottom=toplen+(bottomlen-toplen)/2+100
                End If
        End If
 
        Jpeg.Canvas.DrawLine tmpleft,tmptop,tmpright,tmpbottom
        Jpeg.Canvas.Font.Color=vbRed   '红颜色
        Jpeg.Canvas.Font.Bold=True '是否加粗
        Jpeg.Canvas.Print tmpright,tmpbottom,str
        Jpeg.Canvas.DrawBar 0,0,Jpeg.OriginalWidth,Jpeg.OriginalHeight
        Jpeg.Save filename
        Jpeg.Close
        Set Jpeg=Nothing
End Function

     效果图如下:


 

    在此应该感谢一位朋友,kernzhang,原创是他,曾经他做了个框架方面的视频,而上面有一小部分代码在视频上出现了,再感谢另外一位朋友,是他很有心,硬是把那小段代码从视频上抄下来的。而我做的只是进行了修补,完善,呵呵。。。以上代码还是有不足的地方,有心的朋友可以进行完善,然后再分享给大家。

   lantianwei 发表于:2009-7-20 12:53:27
      不好意思,时间太久,我也忘记到底是谁了,刚仔细查了下,发现确实是kernzhang,现已更正。

   匿名网友 发表于:2009-7-16 16:04:27
      这个是kernzhang写的!怎么变成了梦醒十分,实在是。。。。。。。。。。。。。



     昵称:  
 

                  

联系我们 管理中心 Email:wan1314sq@126.com  QQ:236835793  MSN:lantian.wei@hotmail.com

Copyright@2007-2010 LantianWeiV3.0

备案编号:沪ICP备07012456号