B
Brian Lowe
My web site accepts uploaded photos and stores them in a SQL table as BLObs
so they never touch the filesystem.
I have a way to create a thumbnail version of the uploaded image and store
that in the db too, again without touching metal.
I need a way to overlay some text on the image but I'm stuck.
All the help I find uses files in the filesystem, and when I try to convert
the example to my imagestream model it fails and I can't figure out why. I'm
not big on graphics, so I need some help.
Here's the (working) code I use to get the uploaded image down to a
thumbnail size...
Private Function createThumbnail(ByVal ImageStream As Stream, ByVal tWidth
As Double, ByVal tHeight As Double) As Byte()
Dim g As System.Drawing.Image
Dim thumbSize As Size
Dim imgOutput As Bitmap
Dim imgStream As MemoryStream
Dim thisFormat As Object
Dim imgbin() As Byte
Dim n As Int32
Try
g = System.Drawing.Image.FromStream(ImageStream)
thumbSize = NewthumbSize(g.Width, g.Height, tWidth, tHeight)
imgOutput = New Bitmap(g, thumbSize.Width, thumbSize.Height)
imgStream = New MemoryStream
thisFormat = g.RawFormat
imgOutput.Save(imgStream, thisFormat)
ReDim imgbin(imgStream.Length)
imgStream.Position = 0
n = imgStream.Read(imgbin, 0, imgbin.Length)
Catch ex As Exception
Throw ex
Finally
g.Dispose()
imgOutput.Dispose()
End Try
Return imgbin
End Function
And here's the (non-working) code I need fixing to get text onto the
original image.
Private Function createProof(ByVal ImageStream As Stream) As Byte()
Dim image As System.Drawing.Image
Dim graphic As System.Drawing.Graphics
Dim imgOutput As Bitmap
Dim imgStream As MemoryStream
Dim thisFormat As Object
Dim imgbin() As Byte
Dim n As Int32
Dim myBrush As Drawing2D.HatchBrush
Dim myFont As Font
Try
image = System.Drawing.Image.FromStream(ImageStream)
myBrush = New Drawing2D.HatchBrush(Drawing2D.HatchStyle.Trellis,
Color.FromArgb(127, Color.White))
myFont = New Font("Arial black", 144)
graphic = Graphics.FromImage(image)
graphic.DrawString("PROOF", myFont, myBrush, New RectangleF(10, 10, 100,
200))
imgOutput = New Bitmap(image.Width, image.Height, graphic)
imgStream = New MemoryStream
imgOutput.Save(imgStream, image.RawFormat)
ReDim imgbin(imgStream.Length)
imgStream.Position = 0
n = imgStream.Read(imgbin, 0, imgbin.Length)
Catch ex As Exception
Throw ex
Finally
graphic.Dispose()
imgOutput.Dispose()
End Try
Return imgbin
End Function
Help me out someone, please...
Brian Lowe
---------@
so they never touch the filesystem.
I have a way to create a thumbnail version of the uploaded image and store
that in the db too, again without touching metal.
I need a way to overlay some text on the image but I'm stuck.
All the help I find uses files in the filesystem, and when I try to convert
the example to my imagestream model it fails and I can't figure out why. I'm
not big on graphics, so I need some help.
Here's the (working) code I use to get the uploaded image down to a
thumbnail size...
Private Function createThumbnail(ByVal ImageStream As Stream, ByVal tWidth
As Double, ByVal tHeight As Double) As Byte()
Dim g As System.Drawing.Image
Dim thumbSize As Size
Dim imgOutput As Bitmap
Dim imgStream As MemoryStream
Dim thisFormat As Object
Dim imgbin() As Byte
Dim n As Int32
Try
g = System.Drawing.Image.FromStream(ImageStream)
thumbSize = NewthumbSize(g.Width, g.Height, tWidth, tHeight)
imgOutput = New Bitmap(g, thumbSize.Width, thumbSize.Height)
imgStream = New MemoryStream
thisFormat = g.RawFormat
imgOutput.Save(imgStream, thisFormat)
ReDim imgbin(imgStream.Length)
imgStream.Position = 0
n = imgStream.Read(imgbin, 0, imgbin.Length)
Catch ex As Exception
Throw ex
Finally
g.Dispose()
imgOutput.Dispose()
End Try
Return imgbin
End Function
And here's the (non-working) code I need fixing to get text onto the
original image.
Private Function createProof(ByVal ImageStream As Stream) As Byte()
Dim image As System.Drawing.Image
Dim graphic As System.Drawing.Graphics
Dim imgOutput As Bitmap
Dim imgStream As MemoryStream
Dim thisFormat As Object
Dim imgbin() As Byte
Dim n As Int32
Dim myBrush As Drawing2D.HatchBrush
Dim myFont As Font
Try
image = System.Drawing.Image.FromStream(ImageStream)
myBrush = New Drawing2D.HatchBrush(Drawing2D.HatchStyle.Trellis,
Color.FromArgb(127, Color.White))
myFont = New Font("Arial black", 144)
graphic = Graphics.FromImage(image)
graphic.DrawString("PROOF", myFont, myBrush, New RectangleF(10, 10, 100,
200))
imgOutput = New Bitmap(image.Width, image.Height, graphic)
imgStream = New MemoryStream
imgOutput.Save(imgStream, image.RawFormat)
ReDim imgbin(imgStream.Length)
imgStream.Position = 0
n = imgStream.Read(imgbin, 0, imgbin.Length)
Catch ex As Exception
Throw ex
Finally
graphic.Dispose()
imgOutput.Dispose()
End Try
Return imgbin
End Function
Help me out someone, please...
Brian Lowe
---------@