Thank you very much Ken B
The solution was quite ez and user-friendly.
Here's the code
Code:
Sub DrawOnPicture(ByVal StrInputFilePath As String, ByVal StrOutputFilePath As String, ByVal StrWaterMark As String)
'Construct a Bitmap object from a jpg's filename:
Dim bmp As Bitmap = New Bitmap(StrInputFilePath)
'Obtain a Graphics object from & for that Bitmap:
Dim canvas As Graphics = Graphics.FromImage(bmp)
'Draw the watermark string onto the Bitmap:
canvas.DrawString(strWatermark, _
New Font("Verdana", 14, FontStyle.Bold), _
New SolidBrush(Color.Beige), 0, 0)
'Save the watermarked bitmap to a new file:
bmp.Save(StrOutputFilePath)
End Sub
I have only 1 more problem.
How can I know the Height and Width of the "String" and also the Height and width of the "Picture" (in pixels)?
('cause I want to draw the string on the right side of the pic)
Re: (2005) How can I draw a string on a picture file?
I started to work on this 6 months ago and got side tracked. Looking at my code, I found that you will have a problem writing text on a Format8bppIndexed image.
I have attached an image in the above format. Try your existing code on it and see if it works.
The following code will tell you if an image is a Format8bppIndexed image.
Code:
Public Structure imageInformation
Dim Caption As String
Dim FileExist As Boolean
Dim FileName As String
Dim Height As Single
Dim HorizontalResolution As Single
Dim ImageType As String
Dim Length As Double
Dim Name As String
Dim Palette As Single
Dim PixelFormat As String
Dim Postion As Int16
Dim PrimaryImage As Boolean
Dim ResizeHeight As Single
Dim ResizePercentage As Single
Dim ResizeWidth As Single
Dim SaveAsFileName As String
Dim UpdatedAt As String
Dim ValidImage As Boolean
Dim VerticalResolution As Single
Dim Width As Single
End Structure
Public Sub getImageFileInfo(ByVal fileName As String, ByRef tmpImage As imageInformation)
If Not System.IO.File.Exists(fileName) Then
tmpImage.ValidImage = False
Exit Sub
End If
Try
Dim bit As New Bitmap(fileName)
tmpImage.FileExist = True
tmpImage.FileName = fileName
tmpImage.Height = bit.Height
tmpImage.HorizontalResolution = bit.HorizontalResolution
tmpImage.Length = FileLen(fileName)
tmpImage.PixelFormat = bit.PixelFormat.ToString
tmpImage.ImageType = bit.GetType.ToString
tmpImage.ValidImage = True
tmpImage.VerticalResolution = bit.VerticalResolution
tmpImage.Width = bit.Width
bit.Dispose()
Catch ex As Exception
tmpImage.FileName = fileName
tmpImage.ValidImage = False
Call displayMessage("Exception in getImageFileInfo." & Environment.NewLine & Environment.NewLine & "Error: " & ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
If it is, all you have to do is recreate it as a 24bit image using the following:
Code:
Dim orginalImage As New Bitmap(ImageFileName)
Try
If System.IO.File.Exists(NewImageFileName) Then
System.IO.File.Delete(NewImageFileName)
End If
orginalImage.SetResolution(NewResolution, NewResolution)
orginalImage.Save(NewImageFileName, System.Drawing.Imaging.ImageFormat.Jpeg)
orginalImage.Dispose()
Catch exIO As System.IO.IOException
MessageBox.Show("IOException in reCreateImage." & Environment.NewLine & Environment.NewLine & exIO.Message, "vbPDF Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
Catch ex As Exception
MessageBox.Show("Exception in reCreateImage." & Environment.NewLine & Environment.NewLine & ex.Message, "vbPDF Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
Finally
orginalImage.Dispose()
End Try
The above code is from two different appliactions, but they should work.
I can't help you with your size question at the momment, but will look into it later today.