• AspJpeg2.0组件教程完整版 aspjpeg教程...


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

    AspJpeg最新版本下载、更多例子及详细的在线对象参考手册:
    http://www.aspjpeg.com/

    1、什么是AspJpeg?

    AspJpeg是一款功能强大的基于Microsoft IIS环境的图片处理组件,网络上对其进行详细和深入介绍的中文文章并不多,即使有一般也只是牵涉到图片缩略图和图片水印,这与其为英文版本有着密切的关系。
    AspJpeg可以使用很少的代码在您的ASP/ASP.Net应用程序上动态的创建高质量的缩略图象,支持的图象格式有:JPEG, GIF, BMP, TIFF, PNG

    AspJpeg可以做到:
    图片合并
    图片切割
    图象特效
    数据库支持
    验证码技术
    生成缩略图片
    生成水印图片
    GIF动态图片创建、修改
    ...

    2、AspJpeg功能摘要

    * 支持JPEG, GIF, BMP, TIFF 和 PNG 格式图片来源
    * 图片可以来源于磁盘、内存、或者记录集(数据库)
    * 调整后的图片可以保存到磁盘、内存、或者HTTP流
    * 支持三种更改大小算法:Nearest Neighbor、Bilinear、Bicubic
    * 可以在图片之上添加图画或者文字,支持TrueType和Type 1字体
    * 词语自动换行,文本对齐方式:左、右、居中、两端,图片旋转
    * 支持画中画
    * 剪切,翻转,旋转,锐化,灰度调节
    * 可以调节压缩比率,以得到最佳输出效果和大小
    * 从JPEG图像中提取EXIF和的IPTC元数据
    * 在更改图片的时候保存元数据
    * IPTC元数据的添加和编辑
    * CMYK到RGB转换
    * 棕褐色滤境(老化相片样式)
    * 从图象中对任意象素进行读/写存取
    * PNG Alpha 通道支持
    * GIF透明支持
    * 亮度,对比度和饱和度的调整
    * GIF输出,透明度和动画保存
    * JPEG到GIF格式转换

    3、AspJpeg系统需求

    Windows NT/2000/XP/2003/Vista, and
    IIS 4.0+ and ASP/ASP.NET, or
    Visual Basic 5.0+, or
    Visual C++ 5.0+, or
    any development environment supporting COM.

    4、AspJpeg安装

    全新安装:

    * 到官方网站下载30天全功能评估版本,分32位版(aspjpeg.exe,截止当前版本为2.0,文件大小:1.75M,最后更新日期:2008.01.28)和64位版(aspjpeg64.exe,截止当前版本为2.0,文件大小:1.35M,最后更新日期:2008.02.25,不包含文档)
    * 执行下载的aspjpeg.exe或aspjpeg64.exe
    * 在提示输入序列号的时候输入有效的序列号即可,不输入即代表将使用30天评估版本,可以更改注册表里的RegKey进行注册
    * 如果安装位置磁盘格式为NTFS,则可能出现访问权限问题,需手工设置匿名用户有读取aspjpeg.exe的权限。

    更新安装:
    如果之前有装过其它版本的AspJpeg组件,则需要先卸载原来的组件,再进行新版本的安装。
    先停止IIS:Net Stop iisadmin /y
    卸载旧版组件:regsvr32 /u Path/aspjpeg.dl(Path为安装路径)
    重启IIS:Net Start w3svc

    然后再进行全新安装或复制Bin目录下的AspJpeg.dll文件到安装目录进行手工安装:
    程序代码 程序代码
    regsvr32 Path/aspjpeg.dll(Path为安装路径)

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

    程序代码 程序代码

    Windows Registry Editor Version 5.00

    [HKEY_LOCAL_MACHINESoftwarePersits SoftwareAspJpegRegKey]
    @="17361-38566-42221"

    另外,可以通过代码层由ASPJpeg对象的RegKey属性来设定注册码,如下:
    view plaincopy to clipboardprint?

    1. Set Jpeg = Server.CreateObject("Persits.Jpeg")  
    2. Jpeg.RegKey = "12345-67890-12345" 
    3. ... 

    Set Jpeg = Server.CreateObject("Persits.Jpeg")
    Jpeg.RegKey = "12345-67890-12345"
    ...

    .RegKey指定注册表,如果这个属性没有设置AspJpeg组件将在系统注册表中寻找一个指定的注册码.

    5、如何创建一个AspJpeg实例?

    程序代码 程序代码
    Set Jpeg = Server.CreateObject("Persits.Jpeg")

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

    view plaincopy to clipboardprint?

    1. Set Jpeg = Server.CreateObject("Persits.Jpeg")  
    2. Response.Write Jpeg.Expires

    Set Jpeg = Server.CreateObject("Persits.Jpeg")
    Response.Write Jpeg.Expires

    如果这个属性返回9/9/9999它意味着在使用一个永久的注册码。
    否则为:安装日期加1个月期限

    7、如何用AspJpeg组件创建图片缩略图?
    view plaincopy to clipboardprint?

    1. <%   
    2. Set Jpeg = Server.CreateObject("Persits.Jpeg")    '创建ASPJpeg对象实例  
    3. Path = Server.MapPath("../images/apple.jpg")    '设置图片路径  
    4. Jpeg.Open Path                                    '打开图片  
    5. '调整宽度和高度为原来的50%  
    6. Jpeg.Width = Jpeg.OriginalWidth / 2  
    7. Jpeg.Height = Jpeg.OriginalHeight / 2  
    8. Jpeg.Save Server.MapPath("apple_small.jpg")        '保存图片到磁盘  
    9. Jpeg.Close:Set Jpeg = Nothing 
    10. %>

    <%
    Set Jpeg = Server.CreateObject("Persits.Jpeg")    '创建ASPJpeg对象实例
    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
    %>

    8、如何用AspJpeg组件创建图片水印?
    view plaincopy to clipboardprint?

    1. <%   
    2. Set Jpeg = Server.CreateObject("Persits.Jpeg")   
    3. Jpeg.Open Server.MapPath("2.jpg")   
    4. '开始写文字   
    5. Jpeg.Canvas.Font.Color = &000000    'red 颜色   
    6. Jpeg.Canvas.Font.Family = "Courier New"    '字体   
    7. Jpeg.Canvas.Font.Bold = True    '是否加粗   
    8. Jpeg.Canvas.Print 10, 10, "Copyright (c) XYZ, Inc."   
    9. '打印坐标x 打印坐标y 需要打印的字符   
    10. '以下是对图片进行边框处理   
    11. Jpeg.Canvas.Pen.Color = &H000000    'black 颜色   
    12. Jpeg.Canvas.Pen.Width = 2    '画笔宽度   
    13. Jpeg.Canvas.Brush.Solid = False    '是否加粗处理   
    14. Jpeg.Canvas.Bar 1, 1, Jpeg.Width, Jpeg.Height   
    15. '起始X坐标 起始Y坐标 输入长度 输入高度   
    16. Jpeg.Save Server.MapPath("1.jpg")    '保存   
    17. %>

    <%
    Set Jpeg = Server.CreateObject("Persits.Jpeg")
    Jpeg.Open Server.MapPath("2.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 1, 1, Jpeg.Width, Jpeg.Height
    '起始X坐标 起始Y坐标 输入长度 输入高度
    Jpeg.Save Server.MapPath("1.jpg")    '保存
    %>

    9、如何用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实例对象
    view plaincopy to clipboardprint?

    1. <%  
    2. Set Jpeg1 = Server.CreateObject("Persits.Jpeg")  
    3. Set Jpeg2 = Server.CreateObject("Persits.Jpeg")  
    4. Jpeg1.Open Server.MapPath("t.jpg")  
    5. Jpeg2.Open Server.MapPath("t1.jpg")  
    6. Jpeg1.Canvas.DrawImage 10, 10, Jpeg2 ' optional arguments omitted  
    7. jpeg1.save Server.mappath("tt.jpg")  
    8. %>

    <%
    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")
    %>

    10、如何用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.
    view plaincopy to clipboardprint?

    1. <%  
    2. Set Jpeg = Server.CreateObject("Persits.Jpeg")  
    3. Jpeg.Open Server.MapPath("t.jpg")  
    4. jpeg.Crop 20, 30, jpeg.Width - 20, jpeg.Height - 10   
    5. jpeg.save Server.mappath("tt.jpg")  
    6. Response.write("<img src=tt.jpg>")  
    7. %>

    <%
    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("<img src=tt.jpg>")
    %>

    11、如何用AspJpeg组件创建验证码?

    创建验证码原理上和创建水印差不多。
    view plaincopy to clipboardprint?

    1. <%  
    2. function make_randomize(max_len,w_n) 'max_len 生成长度,w_n:0 可能包含字母,1:只为数字   
    3.     randomize   
    4.     for intcounter=1 to max_len   
    5.         whatnext=int((1-0+1)*rnd+w_n)   
    6.         if whatnext=0 then   
    7.             upper=122   
    8.             lower=97   
    9.         else   
    10.             upper=57   
    11.             lower=48   
    12.         end if   
    13.         strnewpass=strnewpass & chr(int((upper-lower+1)*rnd)+lower)   
    14.     next   
    15.     make_randomize=strnewpass   
    16. end function   
    17.  
    18. '生成安全码的图片。  
    19. random_num=make_randomize(4,1)    '生成4位数字的安全码   
    20. session("random_num")=random_num    '为么调用session,没有session的安全码是完全没有意义的。呵呵 .  
    21.  
    22. Set Jpeg = Server.CreateObject("Persits.Jpeg")    '调用组件   
    23. Jpeg.Open Server.MapPath("t.jpg")    '打开准备的图片   
    24. Jpeg.Canvas.Font.Color = &HFFFFFF   
    25. Jpeg.Canvas.Font.Family = "Arial Black"   
    26. Jpeg.Canvas.Font.Bold = false   
    27. Jpeg.Canvas.PrintText 0, -2, random_num   
    28. jpeg.save Server.MapPath("tt.jpg")    '保存  
    29. %>  
    30. <img src="tt.jpg" border="0" align="absmiddle">

    <%
    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")    '保存
    %>
    <img src="tt.jpg" border="0" align="absmiddle">

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

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

    1. '从内存中打开图象  
    2. Opening Images from Memory   
    3. <% ' Using ADO, open database with an image blob  
    4. strConnect = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("../db/aspjpeg.mdb")  
    5. Set rs = Server.CreateObject("adodb.recordset")  
    6. SQL = "select image_blob from images2 where id = " & Request("id")  
    7. rs.Open SQL, strConnect, 1, 3  
    8. Set Jpeg = Server.CreateObject("Persits.Jpeg")  
    9. ' Open image directly from recordset  
    10. Jpeg.OpenBinary rs("image_blob").Value  
    11. ' Resize  
    12. jpeg.Width = Request("Width")  
    13. ' Set new height, preserve original aspect ratio  
    14. jpeg.Height = jpeg.OriginalHeight * jpeg.Width / jpeg.OriginalWidth  
    15. Jpeg.SendBinary  
    16. rs.Close  
    17. %>  
    18.  
    19. '输出到内存  
    20. <%  
    21. ...  
    22. Set rs = Server.CreateObject("adodb.recordset")  
    23. rs.Open "images", strConnect, 1, 3  
    24. rs.AddNew  
    25. rs("image_blob").Value = Jpeg.Binary  
    26. rs.Update  
    27. ...  
    28. %>

    '从内存中打开图象
    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
    %>

    '输出到内存
    <%
    ...
    Set rs = Server.CreateObject("adodb.recordset")
    rs.Open "images", strConnect, 1, 3
    rs.AddNew
    rs("image_blob").Value = Jpeg.Binary
    rs.Update
    ...
    %>

    13、AspJpeg组件创建GIF动画?
    view plaincopy to clipboardprint?

    1. <%  
    2. Set Jpeg = Server.CreateObject("Persits.Jpeg")  
    3. Set Gif = Jpeg.Gif ' Obtain GIF management object  
    4.  
    5. MarketShare = 6 ' initial market share of hypothetical XYZ company  
    6. ' create a 5-frame animated gif  
    7. For i = 1 to 5  
    8.     Gif.AddFrame 300, 200, 0, 0  
    9.  
    10.     Gif.PenColor = 10  
    11.     Gif.BrushColor = 10  
    12.     Gif.DrawBar 0, 0, 300, 200  
    13.  
    14.     Gif.PenColor = 201  
    15.     Gif.FontFamily = "Courier" 
    16.     Gif.PrintText 18, 15, "XYZ, Inc. Market Share" 
    17.     Gif.PrintText 120, 50, 2002 + i  
    18.       
    19.     ' Draw pie chart  
    20.     Gif.PenColor = 0  
    21.     Gif.BrushColor = 30  
    22.     Gif.DrawPie 150, 130, 50, 0, MarketShare * 360 / 100  
    23.     Gif.BrushColor = 20  
    24.     Gif.DrawPie 150, 130, 50, MarketShare * 360 / 100, 360  
    25.  
    26.     Gif.PenColor = 210  
    27.     Gif.PrintText 200, 100, MarketShare & "%" 
    28.     MarketShare = MarketShare * 2 - 3 ' market share almost doubles every year!  
    29.     ' increase delay on the last frame  
    30.     if i = 5 then Gif.Delay = 300 ' 3 sec  
    31. Next 
    32. ' Save  
    33. Gif.Save Server.MapPath("chart.gif")  
    34. %>  
    35. <IMG SRC="chart.gif">

  • 相关阅读:
    使用 HtmlInputHidden 控件在本页面保持状态和跨页面传值
    asp.net页面回传与js调用服务端事件、PostBack的原理详解
    关于.net委托的一篇妙文
    C# 基础25问
    存储过程分页
    C#中的格式化字符串
    大批量数据的插入之终极性能提升SqlBulkCopy
    统计某个字符串中指定字符串出现的次数
    powerdesigner 15打开pdm文件弹出安装打印机窗口的解决方法
    Convert.ToInt32(),Int.Parse(),Int.TryParse()的区别
  • 原文地址:https://www.cnblogs.com/sczw-maqing/p/3676188.html
Copyright © 2020-2023  润新知