原来是C#的。我转为vb.net了
------------------------------
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Drawing.Drawing2DPublic Class water
    Inherits System.Web.UI.Page#Region " Web 窗体设计器生成的代码 "    '该调用是 Web 窗体设计器所必需的。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()    End Sub
    Protected WithEvents Image1 As System.Web.UI.WebControls.Image
    Protected WithEvents imgtext As System.Web.UI.WebControls.TextBox
    Protected WithEvents tw As System.Web.UI.WebControls.DropDownList
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button    '注意: 以下占位符声明是 Web 窗体设计器所必需的。
    '不要删除或移动它。
    Private designerPlaceholderDeclaration As System.Object    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
        '不要使用代码编辑器修改它。
        InitializeComponent()
    End Sub#End Region    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '在此处放置初始化页的用户代码
        If Not IsPostBack Then        End If
    End Sub    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Copyright As String
        If imgtext.Text <> "" Then
            Copyright = imgtext.Text
        Else
            Copyright = "myx--" & Date.Now.ToString
        End If        'create a image object containing the photograph to water
        Dim imgPhoto As Image = Image.FromFile(Server.MapPath("water_photo.jpg"))
        Dim phWidth As Integer = imgPhoto.Width
        Dim phHeight As Integer = imgPhoto.Height        'create a Bitmap the Size of the original photograph
        Dim bmPhoto As Bitmap = New Bitmap(phWidth, phHeight, PixelFormat.Format24bppRgb)
        bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution)        'load the Bitmap into a Graphics object 
        Dim grPhoto As Graphics = Graphics.FromImage(bmPhoto)        'create a image object containing the water
        Dim imgWater As Image = New Bitmap(Server.MapPath("water.bmp"))
        Dim wmWidth As Integer = imgWater.Width
        Dim wmHeight As Integer = imgWater.Height        '------------------------------------------------------------
        'Step #1 - Insert Copyright message
        '------------------------------------------------------------        'Set the rendering quality for this Graphics object
        grPhoto.SmoothingMode = SmoothingMode.AntiAlias        'Draws the photo Image object at original size to the graphics object.
        grPhoto.DrawImage(imgPhoto, New Rectangle(0, 0, phWidth, phHeight), 0, 0, phWidth, phHeight, GraphicsUnit.Pixel)
        '// Photo Image object
        '// Rectangle structure
        '// x-coordinate of the portion of the source image to draw. 
        '// y-coordinate of the portion of the source image to draw. 
        ' // Width of the portion of the source image to draw. 
        '// Height of the portion of the source image to draw. 
        '// Units of measure 
        '//-------------------------------------------------------
        '//to maximize the size of the Copyright message we will 
        '//test multiple Font sizes to determine the largest posible 
        '//font we can use for the width of the Photograph
        '//define an array of point sizes you would like to consider as possiblities
        '//-------------------------------------------------------
        Dim sizes() As Integer = {16, 14, 12, 10, 8, 6, 4}        Dim crFont As Font = Nothing
        Dim crSize As New SizeF        'Loop through the defined sizes checking the length of the Copyright string
        'If its length in pixles is less then the image width choose this Font size.
        Dim i As Integer
        For i = 0 To 6
            'set a Font object to Arial (i)pt, Bold
            crFont = New Font("arial", sizes(i), FontStyle.Bold)
            'Measure the Copyright string in this Font
            crSize = grPhoto.MeasureString(Copyright, crFont)            If CType(crSize.Width, System.Double) < CType(phWidth, System.Double) Then
                'ToDo: Unsigned Integers not supported
                'ToDo: Unsigned Integers not supported
                Exit For
            End If
        Next i        'Since all photographs will have varying heights, determine a 
        'position 5% from the bottom of the image
        Dim yPixlesFromBottom As Integer = CInt(phHeight * 0.95) '0.05 '--------这里改变上下位置        'Now that we have a point size use the Copyrights string height 
        'to determine a y-coordinate to draw the string of the photograph
        Dim yPosFromBottom As Single = phHeight - yPixlesFromBottom - crSize.Height / 2        'Determine its x-coordinate by calculating the center of the width of the image
        Dim xCenterOfImg As Single = phWidth * 0.25 ' / 2---------这里改变左右位置        'Define the text layout by setting the text alignment to centered
        Dim StrFormat As New StringFormat
        StrFormat.Alignment = StringAlignment.Center        'define a Brush which is semi trasparent black (Alpha set to 153)
        Dim semiTransBrush2 As New SolidBrush(Color.FromArgb(153, 0, 0, 0))        'Draw the Copyright string
        grPhoto.DrawString(Copyright, crFont, semiTransBrush2, New PointF(xCenterOfImg + 1, yPosFromBottom + 1), StrFormat) 'string of text
        'font
        'Brush
        'Position        'define a Brush which is semi trasparent white (Alpha set to 153)
        Dim semiTransBrush As New SolidBrush(Color.FromArgb(153, 255, 255, 255))        'Draw the Copyright string a second time to create a shadow effect
        'Make sure to move this text 1 pixel to the right and down 1 pixel
        grPhoto.DrawString(Copyright, crFont, semiTransBrush, New PointF(xCenterOfImg, yPosFromBottom), StrFormat) 'string of text
        'font
        'Brush
        'Position
        'Text alignment

解决方案 »

  1.   

    '------------------------------------------------------------
            'Step #2 - Insert Water image
            '------------------------------------------------------------
            'Create a Bitmap based on the previously modified photograph Bitmap
            Dim bmWater As New Bitmap(bmPhoto)
            bmWater.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution)
            'Load this Bitmap into a new Graphic Object
            Dim grWater As Graphics = Graphics.FromImage(bmWater)        'To achieve a transulcent water we will apply (2) color 
            'manipulations by defineing a ImageAttributes object and 
            'seting (2) of its properties.
            Dim imageAttributes As New ImageAttributes        'The first step in manipulating the water image is to replace 
            'the background color with one that is trasparent (Alpha=0, R=0, G=0, B=0)
            'to do this we will use a Colormap and use this to define a RemapTable
            'Dim colorMap As New ColorMap        Dim myColorMap(0) As ColorMap
            myColorMap(0) = New ColorMap        'My water was defined with a background of 100% Green this will
            'be the color we search for and replace with transparency
            myColorMap(0).OldColor = Color.FromArgb(255, 0, 255, 0)
            myColorMap(0).NewColor = Color.FromArgb(0, 0, 0, 0)        Dim remapTable As ColorMap() = myColorMap        imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap)        'The second color manipulation is used to change the opacity of the 
            'water.  This is done by applying a 5x5 matrix that contains the 
            'coordinates for the RGBA space.  By setting the 3rd row and 3rd column 
            'to 0.3f we achive a level of opacity
            Dim colorMatrixElements As Single()() = {New Single() {1.0F, 0.0F, 0.0F, 0.0F, 0.0F}, New Single() {0.0F, 1.0F, 0.0F, 0.0F, 0.0F}, New Single() {0.0F, 0.0F, 1.0F, 0.0F, 0.0F}, New Single() {0.0F, 0.0F, 0.0F, 0.3F, 0.0F}, New Single() {0.0F, 0.0F, 0.0F, 0.0F, 1.0F}}
            Dim wmColorMatrix As New ColorMatrix(colorMatrixElements)        imageAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap)        'For this example we will place the water in the upper right
            'hand corner of the photograph. offset down 10 pixels and to the 
            'left 10 pixles
            Dim xPosOfWm As Integer = (phWidth - wmWidth) * 0.25  'phWidth - wmWidth - 10
            Dim yPosOfWm As Integer = (phHeight - wmHeight) * 0.85 '10        grWater.DrawImage(imgWater, New Rectangle(xPosOfWm, yPosOfWm, wmWidth, wmHeight), 0, 0, wmWidth, wmHeight, GraphicsUnit.Pixel, imageAttributes)
            'Set the detination Position
            ' x-coordinate of the portion of the source image to draw. 
            ' y-coordinate of the portion of the source image to draw. 
            ' Water Width
            ' Water Height
            ' Unit of measurment
            'ImageAttributes Object
            'Replace the original photgraphs bitmap with the new Bitmap
            imgPhoto = bmWater
            grPhoto.Dispose()
            grWater.Dispose()        'save new image to file system.
            imgPhoto.Save(Server.MapPath("water.aspx").Replace("water.aspx", "") & "water_final.jpg", ImageFormat.Jpeg)
            imgPhoto.Dispose()
            imgWater.Dispose()
            Image1.ImageUrl = "water_final.jpg"
            Response.Write(Server.MapPath("water.aspx"))    End Sub
    End Class
      

  2.   

    原来地址:Creating a Watered Photograph with GDI+ for .NEThttp://www.codeproject.com/csharp/water.asp
      

  3.   

    能否给一个C#的源文件
    邮件:[email protected]