【原创】web画图工具ShotGraph攻略

本文介绍了ShotGraph的使用环境,包括Visual Basic、VBScript等。阐述了ShotGraph基本知识,如创建图像空间。还给出图像创建的步骤,包括建立对象、定义图像空间大小等,并展示了VBScript代码示例。基本功能可满足多数需求,更多内容可查看官网。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

5iChina.Net原创,尊重知识

ShotGraph 能在以下的环境中使用:

  1. Visual Basic
  2. VBScript
  3. Visual Basic for applications (VBA), Word, Excel, etc.
  4. Active Server Pages (ASP) engine with Internet Information Server
  5. Perl for Windows
  6. others

ShotGraph 基本知识

通过你的程序创建的ShotGraph对象的实例大部分都有图像空间(imagespace), 图像空间是一种用来存储ShotGraph对象创建的数据结构,而ShotGraph对象控制和操作图像的数据。因此,如果你想用ShotGraph来创建或者操作图像文件,就应当创建图像空间。

创建的对象最多有两个图像空间。一个是首要图像空间(primary imagespace),另外一个就是次要图像空间(secondary imagespace)。首要图像空间由CreateImage方法创建。事实上,这个方法可以在几乎所有的script脚本中可以调用。

次要图像空间,也叫‘本地粘贴板(local clipboard)’由InitClipboard方法创建。次要图像空间作为一个缓存来保持图像的整体或者部分地转换,例如:拷贝、伸展、透明等操作。

画图要使用首要图像空间和次要图像空间来,从已经存在的图片中装载,只需要使用首要图像空间的GifImage,JpegImage等方法。

Step by step

这是一个图像创建的基本功能: 写文本,基本图形等等.

  1. 首先建立一个对象 "shotgraph.image".
  2. 调用 CreateImage 方法定义必要的首要图像空间大小。
  3.  ReadImage. 用ReadImage 方法调用一个已经存在的图像到首要图像空间中作为背景。
  4. 调用 SetColor 方法来定义颜色。
  5. FillRect 方法用来清除图像空间。
  6. 调用必要的方法来画图.
  7. 调用GifImage (JpegImage etc.) 方法来写文件

VBScript 中的代码:

'Creating the object
set obj=CreateObject("shotgraph.image")

size=201
'Calling the CreateImage method
obj.CreateImage size,size,4

'Set 4 colors for drawing
obj.SetColor 0,255,255,255
obj.SetColor 1,0,0,0
obj.SetColor 2,255,108,0
obj.SetColor 3,0,0,204

'Crearing the painting area with color 0
obj.SetBgColor 0
obj.FillRect 0,0,size-1,size-1

'Color 0 will be used for drawing
obj.SetDrawColor 1
'Drawing the line
obj.Line size-1,0,0,size-1
'Color 2 will be used for filling
obj.SetBgColor 2
'Draw the big circle
obj.Ellipse 5,5,size-6,size-6
'Color 2 will be used for filling
obj.SetBgColor 3
'Draw the small circle
obj.Ellipse 5,(size-5)/4,size/2,(size-5)*3/4

'Create the image file named test.gif
obj.GifImage 0,1,"test.gif"


asp中的代码:


Response.ContentType="image/gif"
set obj=Server.CreateObject("shotgraph.image")

size=201
obj.CreateImage size,size,4
obj.SetColor 0,255,255,255
obj.SetColor 1,0,0,0
obj.SetColor 2,255,108,0
obj.SetColor 3,0,0,204
obj.SetBgColor 0
obj.FillRect 0,0,size-1,size-1

obj.SetDrawColor 1
obj.Line size-1,0,0,size-1
obj.SetBgColor 2
obj.Ellipse 5,5,size-6,size-6
obj.SetBgColor 3
obj.Ellipse 5,(size-5)/4,size/2,(size-5)*3/4

img=obj.GifImage(0,1,"")
Response.BinaryWrite img
Perl中的代码:
$obj=CreateObject("shotgraph.image")

$size=201
$obj->CreateImage($size,$size,4)
$obj->SetColor(0,255,255,255)
$obj->SetColor(1,0,0,0)
$obj->SetColor(2,255,108,0)
$obj->SetColor(3,0,0,204)
$obj->SetBgColor(0)
$obj->FillRect(0,0,$size-1,$size-1)

$obj->SetDrawColor(1)
$obj->Line($size-1,0,0,$size-1)
$obj->SetBgColor(2)
$obj->Ellipse(5,5,$size-6,$size-6)
$obj->SetBgColor(3)
$obj->Ellipse(5,($size-5)/4,$size/2,($size-5)*3/4)

$obj->GifImage(0,1,"test.gif")
api大全
http://www.shotgraph.com/api.htm

组件下载地址
http://www.shotgraph.com/download.htm

注意:如果要用到ShotGraph的全部功能,就要money了,不过基本的功能,应该可以满足大家的大部分需求了。呵呵。。。

更多内容可以参看网站
http://www.shotgraph.com/

这个组建已经不太好找了,以前在国外网站上下载到的! 共享给大家! 大家经常在网上登陆的时候经常会看到让你输入验证码,有的是文字的,有的呢是图片,比如chinaren.com校友录中留言的时候,我们就会看到数字图片验证码;网上关于数字文字验证码实现方法的相关资料很多,而我们这里介绍的是数字和字母随机组成的并且生成图片的验证码的实现方法。看起来很复杂、其实很简单的,大家跟着我往下看: 首先,我们先介绍一下设计思路,数字和字母的随机组合生成验证码,然后将验证码生成图片,这里“数字和字母的组合”应该是随机取出来的;如果是专门的数字验证码,我们可以这样实现: ycodenum=4 '验证码的位数,或者说成个数 for i=1 to ycodenum Randomize '初始化随机数发生器 ycode=ycode&Int((9*Rnd)) 'rnd是随机数,从0到1之间的任意实数,这里获得0到9之间的整数 next response.write ycode '就可以输出数字验证码(4位) 然而,我们要让数字和字母同样随机生成,这里我们可以用到数组来实现这种效果,如下: ychar="0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z" '将数字和大写字母组成一个字符串 yc=split(char,",") '将字符串生成数组 ycodenum=4 for i=1 to ycodenum Randomize ycode=ycode&yc(Int((35*Rnd))) '数组一般从0开始读取,所以这里为35*Rnd next response.write ycode 现在看看输出结果是不是数字和字母随机组合的呢? 下面看看怎样生成图片,这个也许有些朋友知道:asp不能生成图片,必须使用asp组件。不错,我们这里使用的是ASP图象组件shotgraph。有一点大家注意,服务器不是自己的不能用哦,因为你装不了这组件。 我们看看生成图片的代码: ychar="0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z" '将数字和大写字母组成一个字符串 yc=split(char,",") '将字符串生成数组 ycodenum=4 for i=1 to ycodenum Randomize ycode=ycode&yc(Int((35*Rnd))) '数组一般从0开始读取,所以这里为35*Rnd next Response.Clear Response.ContentType="image/gif" set obj=Server.CreateObject("shotgraph.image") x=55 '图片的宽 y=26 '图片的高 obj.CreateImage x,y,8 '8是图片的颜色8位 obj.SetColor 0,55,126,222 obj.SetColor 1,255,255,255 obj.CreatePen "PS_SOLID",1,0 obj.SetBgColor 0 obj.Rectangle 0,0,x-1,y-1 obj.SetBkMode "TRANSPARENT" obj.CreateFont "Arial",136,18,1,False,False,False,False obj.SetTextColor 1 obj.TextOut 5,4,ycode&" " img=obj.GifImage(-1,1,"") Response.BinaryWrite (img)
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值