Generate a image on the fly

Posted by Venkat | Labels:

Here we have to discuss about how to create small rectangle with fill color and write text on image
for that you have to use some namespace

Imports System.IO
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Drawing.Text
Imports System.Drawing.Drawing2D

// Code behind file is

Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
Response.Clear() ' make sure Nothing has gone to the client
Dim imgOutput As New Bitmap(120, 30, PixelFormat.Format24bppRgb) ' create a New 24bit, 120x30 pixel image
Dim g As Graphics = Graphics.FromImage(imgOutput) ' create a New graphic object from the above bmp
' Application("intPageCount") += 1 ' really dumb page counter

g.Clear(Color.DarkGreen) ' blank the image
g.SmoothingMode = SmoothingMode.HighQuality ' antialias objects
' draw the number on the image canvas in verdana 10pt font bold
'g.DrawString("Count: " & Application("intPageCount"), New Font("verdana", 14, FontStyle.Bold), SystemBrushes.WindowText, New PointF(2, 2))
g.DrawString("A 2", New Font("verdana", 14, FontStyle.Bold), SystemBrushes.WindowText, New PointF(6, 6))
' draw a graduated fill across the image
g.FillRectangle(New LinearGradientBrush(New Point(0, 0), New Point(200, 200), Color.FromArgb(0, 0, 0, 0), Color.FromArgb(255, 255, 255, 255)), 0, 0, 120, 120)
imgOutput.Save(Response.OutputStream, ImageFormat.Jpeg) ' output to the user
' tidy up
g.Dispose()
imgOutput.Dispose()
Response.End()
End Sub

All the best

0 comments:

Post a Comment

Thanks for the Comments.

PayOffers.in