Write text on image

Posted by Venkat | Labels: ,

Here we have to discuss about how to write a text on image

this is the code written in Button_Click Event


Dim i As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath("~/Availability/2_type_A.JPG"))
Dim b As Drawing.Bitmap
b = Sold(i, i.Width, i.Height, "Sold", 100)
b.Save(Server.MapPath("~/Updated/2_type_A.JPG"), System.Drawing.Imaging.ImageFormat.Jpeg)


And also make sure you have store the image in different folder suppose if you getting the image form folder ie: Availability and once written the text on image store it on same folder Availability - this leads to error: Generic Error occured in GDI+. so you have to store it on differen folder
this is the functions which is going to write the text on image



Private Function Sold(ByVal resim As System.Drawing.Image, ByVal genislik As Integer, ByVal yukseklik As Integer, ByVal yazilacak As String, ByVal font As Single) As Bitmap
Dim resmim As New Bitmap(resim, genislik, yukseklik)
Dim graf As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(resmim)
Dim firca As System.Drawing.SolidBrush = New SolidBrush(System.Drawing.Color.Red)
Dim fnt As System.Drawing.Font = New Font("Verdana", font)
Dim size As System.Drawing.SizeF = New SizeF(400, 400) ' this is the size of the font ie: width and height
Dim coor As System.Drawing.PointF = New PointF(XTextBox.Text, YTextBox.Text) ' this is X and Y Co-ordinates where you going to write the text on image
Dim kutu As System.Drawing.RectangleF = New RectangleF(coor, size)
Dim sf As New StringFormat()
sf.FormatFlags = StringFormatFlags.NoWrap
graf.DrawString(yazilacak, fnt, firca, kutu, sf)
Return resmim
End Function



0 comments:

Post a Comment

Thanks for the Comments.

PayOffers.in