您所在的位置:首页 >>帮助中心 >>虚拟主机问题

ASPJpeG组件


文章来源:原创 发布者:八戒发布时间:2014/10/13 20:25:50【打印此页】 【关闭

    AspJpeg简介

    AspJpeg是一款功能强大的基于Microsoft IIS环境的图片处理组件,网络上对其进行详细和深入介绍的中文文章并不多,即使有一般也只是牵涉到图片缩略图和图片水印,这与其为英文版本有着密切的关系。

    AspJpeg可以使用很少的代码在您的ASP/ASP.Net应用程序上动态的创建高质量的缩略图象,支持的图象格式有:JPEG, GIF, BMP, TIFF, PNG。

    AspJpeg主要可以做到:生成缩略图片、生成水印图片、图片合并、图片切割、数据库支持、安全码技术

ASPJPEG是一款功能相当强大的图象处理组件,用它可以轻松地做出图片的缩略图和为图片加上水印功能。




    AspJpeg安装

在AspJpeg安装过程中输入序列号即可,如果安装位置磁盘格式为NTFS,则可能出现访问权限问题,需手工设置安装目录对Everyone有访问权限。

更新安装:


如果之前有装过其它版本的AspJpeg组件,则需要先卸载原来的组件,再进行新版本的安装。

先停止IIS

Net Stop iisadmin /y

卸载旧版组件

regsvr32 /u Path/aspjpeg.dl(Path为安装路径)

重启IIS

Net Start w3svc

然后再进行全新安装或复制AspJpeg.dll文件到安装目录进行手工安装:

regsvr32 Path/aspjpeg.dll(Path为安装路径)

如果在正常安装过程中没有输入序列号或手工安装则必须在注册表中加入以下项,为方便起见您可以直接将以下代码保存为.reg文档并导入注册表:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Persits Software\AspJpeg\RegKey]

@="48958-77556-02411"


   AspJpeg使用方法


如何创建一个AspJpeg实例?


Set Jpeg = Server.CreateObject("Persits.Jpeg")

如何查看到期时间(是否注册成功)?


Set Jpeg = Server.CreateObject("Persits.Jpeg")

Response.Write Jpeg.Expires

注册成功则到期时间为:9999-9-9

否则为:安装日期加1个月期限

如何用AspJpeg组件生成图片缩略图?


<%

Set Jpeg = Server.CreateObject("Persits.Jpeg") '创建实例

Path = Server.MapPath("../images/apple.jpg") '处理图片路径

Jpeg.Open Path '打开图片

'调整宽度和高度为原来的50%

Jpeg.Width = Jpeg.OriginalWidth / 2

Jpeg.Height = Jpeg.OriginalHeight / 2

Jpeg.Save Server.MapPath("apple_small.jpg") '保存图片到磁盘

Jpeg.Close:Set Jpeg = Nothing

%>

如何用AspJpeg组件生成图片水印?


<%

Set Jpeg = Server.CreateObject("Persits.Jpeg")

Jpeg.Open Server.MapPath("images/dodge_viper.jpg")

开始写文字

Jpeg.Canvas.Font.Color = &000000'' red 颜色

Jpeg.Canvas.Font.Family = "Courier New" 字体

Jpeg.Canvas.Font.Bold = True 是否加粗

Jpeg.Canvas.Print 10, 10, "Copyright (c) XYZ, Inc."

打印坐标x 打印坐标y 需要打印的字符

以下是对图片进行边框处理

Jpeg.Canvas.Pen.Color = &H000000'' black 颜色

Jpeg.Canvas.Pen.Width = 2 画笔宽度

Jpeg.Canvas.Brush.Solid = False 是否加粗处理

Jpeg.Canvas.Bar left, top, right, bottom ' 左,上,右,下

Jpeg.Save Server.MapPath("images/dodge_viper_framed.jpg") 保存

%>

如何用AspJpeg组件进行图片合并?


AspJpeg 1.3+ enables you to place images on top of each other via the method DrawImage. To use this method, you must create two instances of the AspJpeg objects and populate both of them with images via calls to Open (or OpenBinary). When calling Canvas.DrawImage, the 2nd instance of AspJpeg is passed as an argument to this method, along with the X and Y offsets (in pixels):

使用该方法,您必需创建两个AspJpeg实例对象

<%

Set Jpeg1 = Server.CreateObject("Persits.Jpeg")

Set Jpeg2 = Server.CreateObject("Persits.Jpeg")

Jpeg1.Open Server.MapPath("t.jpg")

Jpeg2.Open Server.MapPath("t1.jpg")

Jpeg1.Canvas.DrawImage 10, 10, Jpeg2 ' optional arguments omitted

jpeg1.save Server.mappath("tt.jpg")

%>

如何用AspJpeg组件进行图片切割?


AspJpeg 1.1+ is also capable of cutting off edges from, or cropping, the resultant thumbnails via the method Crop(x0, y0, x1, y1). The size of the cropped image is specified by the coordinates of the upper-left and lower-right corners within the resultant thumbnail, not the original large image.

<%

Set Jpeg = Server.CreateObject("Persits.Jpeg")

Jpeg.Open Server.MapPath("t.jpg")

jpeg.Crop 20, 30, jpeg.Width - 20, jpeg.Height - 10

jpeg.save Server.mappath("tt.jpg")

Response.write("")

%>

如何用AspJpeg组件创建安全码?


创建安全码原理上和创建水印差不多。

<%

function make_randomize(max_len,w_n) 'max_len 生成长度,w_n:0 可能包含字母,1:只为数字

randomize

for intcounter=1 to max_len

whatnext=int((1-0+1)*rnd+w_n)

if whatnext=0 then

upper=122

lower=97

else

upper=57

lower=48

end if

strnewpass=strnewpass & chr(int((upper-lower+1)*rnd)+lower)

next

make_randomize=strnewpass

end function

'生成安全码的图片。

random_num=make_randomize(4,1) ''生成4位数字的安全码

session("random_num")=random_num '为么调用session,没有session的安全码是完全没有意义的。呵呵 .

Set Jpeg = Server.CreateObject("Persits.Jpeg") '调用组件

Jpeg.Open Server.MapPath("t.jpg") '打开准备的图片

Jpeg.Canvas.Font.Color = &HFFFFFF

Jpeg.Canvas.Font.Family = "Arial Black"

Jpeg.Canvas.Font.Bold = false

Jpeg.Canvas.PrintText 0, -2, random_num

jpeg.save Server.MapPath("tt.jpg") '保存

%>

如何让AspJpeg组件支援数据库?


图片存进数据库只能以二进制数据保存,这里即利用AspJpeg的Binary方法,下面以两个AspJpeg用户手册上的代码为例,具体请参考AspJpeg用户手册:

Opening Images from Memory

<% ' Using ADO, open database with an image blob

strConnect = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("../db/aspjpeg.mdb")

Set rs = Server.CreateObject("adodb.recordset")

SQL = "select image_blob from images2 where id = " & Request("id")

rs.Open SQL, strConnect, 1, 3

Set Jpeg = Server.CreateObject("Persits.Jpeg")

' Open image directly from recordset

Jpeg.OpenBinary rs("image_blob").Value

' Resize

jpeg.Width = Request("Width")

' Set new height, preserve original aspect ratio

jpeg.Height = jpeg.OriginalHeight * jpeg.Width / jpeg.OriginalWidth

Jpeg.SendBinary

rs.Close

%>

Output to Memory

<%

...

Set rs = Server.CreateObject("adodb.recordset")

rs.Open "images", strConnect, 1, 3

rs.AddNew

rs("image_blob").Value = Jpeg.Binary

rs.Update

...

%>

更多方法介绍:


Canvas.Line(Left, Top, Right, Bottom)

画一条直线

Canvas.Ellipse(Left, Top, Right, Bottom)

画出一个椭圆

Canvas.Circle(X, Y, Radius)

画出一个圆

Canvas.Bar(Left, Top, Right, Bottom)

画出一个长方形,上面有代码介绍了

Canvas.Font.ShadowColor

文字阴影颜色

Canvas.Font.ShadowXOffset As Long

阴影X坐标设定

Canvas.Font.ShadowYOffset As Long

Y坐标设定

Canvas.Font.BkMode As String


值班QQ
域名、虚拟主机、云服务器产品售后
IDC托管、租用、机柜大带宽产品售后
值班电话
返回顶部