locked
Semi Transparent Image RRS feed

  • Question

  • User-964190934 posted
    I am trying to apply a watermark to my product images. I am using the ImageHandler as used on CodeProjects. Rather than applying text as a watermark, I am using another image (the company logo) as my watermark, but have been unsuccessful setting the transparency (alpha value??) of the watermark image. Anyone got any ideas / snippets, Thanks, Mark
    Wednesday, September 1, 2004 5:45 AM

All replies

  • User-964190934 posted
    s'ok, i got it Public Sub AddWaterMark(ByVal sWatermark As String) 'get the drawing canvas (graphics object) from the bitmap Dim canvas As Graphics Try canvas = Graphics.FromImage(bmp) Catch e As Exception 'You cannot create a Graphics object from an image with an indexed pixel format. 'If you want to open this image and draw on it you need to do the following... 'size the new bitmap to the source bitmaps dimensions Dim bmpNew As Bitmap = New Bitmap(bmp.Width, bmp.Height) canvas = Graphics.FromImage(bmpNew) 'draw the old bitmaps contents to the new bitmap paint the entire region of the old bitmap to the 'new bitmap..use the rectangle type to select area of the source image canvas.DrawImage(bmp, New Rectangle(0, 0, bmpNew.Width, bmpNew.Height), 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel) bmp = bmpNew End Try Dim imgWaterLogo As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath("~/Images/Colmore.gif")) Dim clrMatrix As New ColorMatrix clrMatrix.Matrix00 = 1.0F ' Red clrMatrix.Matrix11 = 1.0F ' Green clrMatrix.Matrix22 = 1.0F ' Blue clrMatrix.Matrix33 = 0.5F ' alpha clrMatrix.Matrix44 = 1.0F ' w Dim imageAttr As System.Drawing.Imaging.ImageAttributes = New System.Drawing.Imaging.ImageAttributes imageAttr.SetColorMatrix(clrMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap) 'imageAttr.SetColorKey(Color.FromArgb(100, 0, 0, 0), Color.FromArgb(100, 255, 255, 255)) ' Create parallelogram for drawing image. Dim x, y As Single x = 50 y = 50 Dim ulCorner1 As New Point(x, y) Dim urCorner1 As New Point(x + imgWaterLogo.Width, y) Dim llCorner1 As New Point(x, y + imgWaterLogo.Height) Dim destPara1 As Point() = {ulCorner1, urCorner1, llCorner1} Dim srcRect As New System.Drawing.Rectangle(0, 0, imgWaterLogo.Width, imgWaterLogo.Height) Dim srcUnit As System.Drawing.GraphicsUnit = GraphicsUnit.Pixel canvas.DrawImage(imgWaterLogo, destPara1, srcRect, srcUnit, imageAttr) End Sub
    Wednesday, September 1, 2004 7:05 AM