程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> ASP編程 >> 關於ASP編程 >> asp水印組件之AspJpeg的結合代碼實例

asp水印組件之AspJpeg的結合代碼實例

編輯:關於ASP編程
1、什麼是AspJpeg?
AspJpeg是一款功能強大的基於Microsoft IIS環境的圖片處理組件,網絡上對其進行詳細和深入介紹的中文文章並不多,即使有一般也只是牽涉到圖片縮略圖和圖片水印,這與其為英文版本有著密切的關系。
AspJpeg可以使用很少的代碼在您的ASP/ASP.Net應用程序上動態的創建高質量的縮略圖象,支持的圖象格式有:JPEG, GIF, BMP, TIFF, PNG

AspJpeg主要可以做到:

生成縮略圖片
生成水印圖片
圖片合並
圖片切割
數據庫支持
安全碼技術

2、AspJpeg功能摘要
支持JPEG, GIF, BMP, TIFF 和 PNG 格式圖片. 輸出格式始終為 JPEG
源圖片可以來源於磁盤、內存、或者記錄集(數據庫)
縮略圖片可以保存到磁盤、內存、或者HTTP流
支持三種更改大小方式: nearest-neighbor, bilinear, and bicubic. 
可以在圖片之上添加圖片或者文字. 
支持畫中畫
支持復制,反轉,旋轉,銳化,灰度調節.
可以調節壓縮比率,以得到最佳輸出效果和大小. 
從Jpeg圖片中抽取EXIF 和 IPTC數據.
CMYK-RGB轉換
Read/write access to individual pixels of an image. (從圖象中對任意象素進行讀/寫存取。)

3、AspJpeg系統需求
Windows 95/98/NT/2000/XP/2003, 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安裝
全新安裝:
在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\AspUpload3\RegKey]
@="21764-40765-60456"


5、如何創建一個AspJpeg實例?
Set Jpeg = Server.CreateObject("Persits.Jpeg")



6、如何查看到期時間(是否注冊成功)?
Set Jpeg = Server.CreateObject("Persits.Jpeg")
Response.Write Jpeg.Expires


注冊成功則到期時間為:9999-9-9
否則為:安裝日期加1個月期限

7、如何用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
%>


8、如何用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 1, 1, Jpeg.Width, Jpeg.Height 
起始X坐標 起始Y坐標 輸入長度 輸入高度 
Jpeg.Save Server.MapPath("images/dodge_viper_framed.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實例對象
<%
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. 
<%
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組件創建安全碼?
創建安全碼原理上和創建水印差不多。
<%
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用戶手冊:
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
...
%> 
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved