ASP.NET(VB)應(yīng)用之圖片增加水印文字淺析
作者:佚名
ASP.NET(VB)應(yīng)用之圖片增加水印文字向你介紹了使用ASP.NET(VB)為圖片增加水印文字的具體事例解析,使你更加直觀的了解這一應(yīng)用。
ASP.NET(VB) 給圖片增加水印文字:指定要添加水印文字的圖片
- DimimgAsImage=Image.FromFile(Server.MapPath("~/upload/1.jpg"))
- '創(chuàng)建一個(gè)位圖對(duì)象以供繪圖操作(不能直接操作BMP以外的格式,可能吧)
- DimbitmapAsNewBitmap(343,498)
- '要繪制文字的字體
- DimfAsNewFont("微軟雅黑",16,FontStyle.Underline)
- '文字內(nèi)容
- DimstrAsString=TextBox5.Text
- '創(chuàng)建一個(gè)繪制圖像的對(duì)象
- DimgAsGraphics=Graphics.FromImage(bitmap)
- '線條的坐標(biāo)
- Dimx1,x2,y1,y2,s1,s2AsInteger
- x1=CType(TextBox1.Text,Integer)
- x2=CType(TextBox2.Text,Integer)
- y1=CType(TextBox3.Text,Integer)
- y2=CType(TextBox4.Text,Integer)
- '文字的坐標(biāo)
- s1=CType(TextBox6.Text,Integer)
- s2=CType(TextBox7.Text,Integer)
- '限定繪圖的范圍
- g.DrawImage(img,0,0,343,498)
- '繪制文字
- g.DrawString(str,f,Brushes.Red,s1,s2)
- '繪制線條
- g.DrawLine(Pens.White,x1,x2,y1,y2)
- '繪制完成后的保存路徑
- DimiimgAsString="~/upload/11.jpg"
- Dimimg1AsString=Server.MapPath(iimg)
- 'JPG圖像質(zhì)量參數(shù)
- DimepAsImaging.EncoderParameters=NewImaging.EncoderParameters
- '圖像質(zhì)量值
- ep.Param(0)=NewImaging.EncoderParameter(Imaging.Encoder.Quality,CLng(TextBox8.Text))
- '以流方式讀取圖像內(nèi)容
- DimcodecsAsImaging.ImageCodecInfo()=Imaging.ImageCodecInfo.GetImageEncoders
- DimiciAsImaging.ImageCodecInfo
- ForEachcodecAsImaging.ImageCodecInfoIncodecs
- Ifcodec.MimeType="image/jpeg"Then
- ici=codec
- EndIf
- Next
- '保存繪制好的圖像
- bitmap.Save(img1,ici,ep)
- Image1.ImageUrl=iimg
- '釋放對(duì)象
- g.Dispose()
- bitmap.Dispose()
- img.Dispose()
ASP.NET(VB)應(yīng)用之圖片增加水印文字的相關(guān)信息就向你介紹到這里,希望對(duì)你有所幫助。
【編輯推薦】
責(zé)任編輯:仲衡
來(lái)源:
cnbolgs