Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2015
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. Dim watermarkText As String = "Name"
  2. Dim watermarkText1 As String = "Nameeeee1111"
  3.  
  4. 'Get the file name.
  5. Dim fileName As String = imagepath
  6. 'Dim fs As FileStream = File.OpenRead(filepath)
  7. 'Read the File into a Bitmap.
  8. Using bmp As New Bitmap(File.OpenRead(filepath))
  9. Using grp As Graphics = Graphics.FromImage(bmp)
  10.  
  11. 'Set the Color of the Watermark text.
  12. Dim brush As Brush = New SolidBrush(Color.FromArgb(100, Color.Gray))
  13. 'New SolidBrush(Color.Gray)
  14.  
  15. 'Set the Font and its size.
  16. Dim font As Font = New System.Drawing.Font("Times New Roman", 200, FontStyle.Bold, GraphicsUnit.Pixel)
  17.  
  18. Dim font1 As Font = New System.Drawing.Font("Times New Roman", 40, FontStyle.Bold, GraphicsUnit.Pixel)
  19.  
  20. 'Determine the size of the Watermark text.
  21. Dim textSize As New SizeF()
  22. textSize = grp.MeasureString(watermarkText, font)
  23.  
  24.  
  25. Dim textSize1 As New SizeF()
  26. textSize1 = grp.MeasureString(watermarkText1, font1)
  27.  
  28. 'Position the text and draw it on the image.
  29. ' Dim position As New Point((bmp.Width / 2), (bmp.Height / 2))
  30. Dim position As New Point((bmp.Width / 2 - (CInt(textSize.Width) / 2)), (bmp.Height / 2 - (textSize.Height / 2)))
  31. grp.DrawString(watermarkText, font, brush, position)
  32.  
  33. Dim position1 As New Point((bmp.Width / 2 - (CInt(textSize.Width) / 2 - 200)), (bmp.Height / 2 - (textSize.Height / 2 - 200)))
  34. grp.DrawString(watermarkText1, font1, brush, position1)
  35.  
  36. Dim p As String
  37. p = Server.MapPath("reza" & newpath)
  38.  
  39. bmp.Save(p, System.Drawing.Imaging.ImageFormat.Jpeg)
  40. bmp.Dispose()
  41.  
  42. brush.Dispose()
  43. font.Dispose()
  44.  
  45. font1.Dispose()
  46. grp.Dispose()
  47.  
  48. GC.Collect()
  49. GC.WaitForPendingFinalizers()
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56. End Using
  57. End Using
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement