ndfweb.cn

AspJpeg 2.0 使用說明


2009-07-23 08:37:04 (6523)



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_MACHINE\Software\Persits Software\AspJpeg\RegKey]
@="17361-38566-42221"



另外,可以通過代碼層由ASPJpeg對象的RegKey屬性來設定注冊碼,如下:

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


.RegKey指定注冊表,如果這個屬性沒有設置AspJpeg組件將在係統注冊表中尋找一個指定的注冊碼.

5、如何創建一個AspJpeg實例?

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



6、如何查看到期時間(是否注冊成功)?

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


如果這個屬性返回9/9/9999它意味著在使用一個永久的注冊碼。
否則為:安裝日期加1個月期限

7、如何用AspJpeg組件創建圖片縮略圖?

  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. %>  



8、如何用AspJpeg組件創建圖片水印?

  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. %>  



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實例對象

  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. %>  



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.

  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. %>  



11、如何用AspJpeg組件創建驗證碼?

  創建驗證碼原理上和創建水印差不多。

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



12、如何讓AspJpeg組件支援數據庫?

  圖片存進數據庫隻能以二進製數據保存,這裏即利用AspJpeg的Binary方法,下麵以兩個AspJpeg用戶手冊上的代碼為例,具體請參考AspJpeg用戶手冊:

  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. %>  



13、AspJpeg組件創建GIF動畫?

  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">  
本文版权:http://www.ndfweb.cn/news-383.html
  NDF俱乐部
  国际域名注册
  建站咨询
简体中文 NDF网站建设淘宝店 | ICO图标在线生成 | 外贸网站建设 | 联系我们
©2007-2025 NDF Corporation 鲁ICP备08005967号 Sitemap - RSSRSS订阅