Joe said:
this file is drawn in VB.NET and input output goes by XmlSerializer.
Therefore, simple output file looks like:
<?xml version="1.0" encoding="utf-8"?>
<DrawablePicture xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="
http://www.w3.org/2001/XMLSchema" BackColor="-1250856">
<DrawableRectangle LineWidth="2" X1="377" Y1="88" X2="323" Y2="130"
ForeColor="-16777216" BackColor="-1" />
</DrawablePicture>
I would like to show it through webpage, but before I need to convert
it into GIF, PNG or any web-image readable file.
Can somebody please put some light on this issue? How would you
achieve that?
Thank you so much!
If you can create an image you don't have to create a file to display the
info on a webpage.
What you want to do is the following:
1. Create a new aspx page in your website
2. For the URL on any page which needs your image set it to the newly
create aspx page. Using the QueryString you can then pass info to the page
which it will use to create an image. You will then write to the Response
object the image. This will allow you to dynamically create images on the
page without actually creating image files.
I have an example of this. I have a button which I use as a Jukebox button.
Rather than creating different ones for each "track number" I simple create
a bitmap using the background of the button and then impose the track number
as text.
Example:
Option Strict On
Option Explicit On
Imports System
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.IO
Imports MusicSiteControls
Partial Class DynamicImage
Inherits System.Web.UI.Page
Public Const imText As String = "ImageText"
Public Const imFolder As String = "ImageFolder"
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim imageFolder As String
Dim imageText As String
Dim bm As Bitmap
Dim ms As MemoryStream
imageFolder = Request.QueryString(imFolder)
imageText = Request.QueryString(imText)
If imageFolder Is Nothing Then
bm = makeImage(imageText)
Else
bm = makeImage(imageFolder, imageText)
End If
If bm Is Nothing Then
bm = New Bitmap(Server.MapPath("~/Images/no-file-32x32.png"))
End If
ms = New MemoryStream
bm.Save(ms, ImageFormat.Jpeg)
Response.ContentType = "image/jgp"
Response.BinaryWrite(ms.ToArray())
End Sub
Private Function makeImage(ByVal imagetext As String) As Bitmap
Dim bm As Bitmap
Dim g As Graphics
Dim bfont As Font
Dim tsize As SizeF
'Dim imageHeight As Integer
'Dim imageWidth As Integer
bfont = New Font("Trebuchet MS", 14)
bm = New Bitmap(Server.MapPath("~/Images/TrackBackground.png"))
g = Graphics.FromImage(bm)
tsize = g.MeasureString(imagetext, bfont)
Dim tx As Single
Dim ty As Single
tx = (bm.Width - tsize.Width) / 2
ty = (bm.Height - tsize.Height) / 2
g.DrawString(imagetext, bfont, New SolidBrush(Color.Black), tx, ty)
g.Dispose()
Return bm
End Function
Private Function makeImage(ByVal imageFolder As String, ByVal imagetext
As String) As Bitmap
Dim bm As Bitmap
'Dim g As Graphics
Dim bfont As Font
'Dim tsize As SizeF
'Dim imageHeight As Integer
'Dim imageWidth As Integer
bfont = New Font("Trebuchet MS", 10)
Dim d As New DAL
Dim folderName As String = d.GetImageFile(CInt(imageFolder))
Dim fn() As String = Directory.GetFiles(folderName, "*.jpg")
If fn.Length = 0 Then
bm = Nothing
Return bm
End If
bm = New Bitmap(fn(0))
'Dim myImg As Bitmap
'Dim myCallback As System.Drawing.Image.GetThumbnailImageAbort
'Dim myPtr As IntPtr
'myImg = DirectCast(bm.GetThumbnailImage(32, 32, myCallback, myPtr),
Bitmap)
'g = Graphics.FromImage(bm)
'g.DrawString(imagetext, bfont, New SolidBrush(Color.Black), 2, 2)
'g.Dispose()
Return bm
End Function
End Class
Hope this helps
Lloyd Sheen