I'm creating a website with dynamically generated header graphics and I'm running into a problem with the server. I don't have all the specs on the server, but is there a more optimized way of creating images that doesn't take up so much CPU resources. The problem I'm having tends to be when there are more than 2 images on the page the script must create. I was reading about octree, but not quite sure how to implement. I'm kind of new to ASP.NET, so any help is much appreciated.
Here's the image creation script:
Here's the image creation script:
Code:
'setup my variables
Dim strText As String = Request("text")
Dim intSize As Integer = 30
' set up memory stream
Dim MemStream As New MemoryStream()
'setup font
Dim privateFontCollection As New PrivateFontCollection()
' to load in the font add the font file to the private collection.
privateFontCollection.AddFontFile(Server.MapPath("\fonts\tradeg_ltc18.ttf"))
Dim thisFont As FontFamily = privateFontCollection.Families(0)
Dim regFont As New Font(thisFont, intSize, FontStyle.Regular, GraphicsUnit.Pixel)
'setup width height
Dim txtpic As New System.Drawing.Bitmap(5000, 5000, PixelFormat.Format32bppArgb)
Dim txtg As Graphics = Graphics.FromImage(txtpic)
Dim dimensions As SizeF = txtg.MeasureString(strText, regFont)
Dim imgWidth As Integer = dimensions.Width
Dim imgHeight As Integer = dimensions.Height
txtpic.Dispose()
txtg.Dispose()
'Dim imgWidth As Integer = 300
'Dim imgHeight As Integer = 50
' set up image and graphic
Dim pic As New System.Drawing.Bitmap(imgWidth, imgHeight, PixelFormat.Format32bppArgb)
Dim g As Graphics = Graphics.FromImage(pic)
' set up pen and brush
Dim TextBrush As SolidBrush = New SolidBrush(Color.FromArgb(255, 0, 0, 0))
' blank the image and set smoothing
'g.Clear(Color.Transparent)
g.Clear(Color.FromArgb(255, 255, 255, 255))
g.SmoothingMode = SmoothingMode.AntiAlias ' antialias objects
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias
'g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit
' draw image
g.DrawString(strText, regFont, TextBrush, New PointF(0, 0))
' set the content type
'Response.ContentType = "image/png"
Response.ContentType = "image/gif"
'Response.ContentType = "image/jpg"
' send the image to the memory stream then output
'pic.Save(MemStream, ImageFormat.Png)
pic.Save(MemStream, ImageFormat.Gif)
'pic.Save(MemStream, ImageFormat.Jpeg)
MemStream.WriteTo(Response.OutputStream)
' tidy up
pic.Dispose()