ASP.NET,VB 给图片增加水印文字

 '指定要添加水印文字的图片

    DimimgAsImage=Image.FromFile(Server.MapPath("~/upload/1.jpg"))

    '创建一个位图对象以供绘图操作(不能直接操作BMP以外的格式,可能吧)

    DimbitmapAsNewBitmap(343,498)

    '要绘制文字的字体

    DimfAsNewFont("微软雅黑",16,FontStyle.Underline)

    '文字内容

    DimstrAsString=TextBox5.Text

    '创建一个绘制图像的对象

    DimgAsGraphics=Graphics.FromImage(bitmap)

    '线条的坐标

    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)

    '文字的坐标

    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图像质量参数

    DimepAsImaging.EncoderParameters=NewImaging.EncoderParameters

    '图像质量值

    ep.Param(0)=NewImaging.EncoderParameter(Imaging.Encoder.Quality,CLng(TextBox8.Text))

    '以流方式读取图像内容

    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

    '释放对象

    g.Dispose()

    bitmap.Dispose()

    img.Dispose()

新闻来自: 新客网(www.xker.com) 详文参考:http://www.xker.com/page/e2008/1215/66441.html