Re: overlay text on uploaded picture

From: Brian Lowe (no_at_reply.address)
Date: 06/22/04


Date: Tue, 22 Jun 2004 16:50:18 +0100


"Patrick Steele [MVP]" <patrick@mvps.org> wrote in message
news:MPG.1b41ed8ac645c1c0989946@msnews.microsoft.com...
> In article <eS3$Eo8VEHA.212@TK2MSFTNGP12.phx.gbl>, no@reply.address

> > ' Use the DrawString() method of the graphics object to
> > ' overlay the text (tell me if I'm wrong, please)
> > graphic.DrawString("PROOF", myFont, myBrush, New RectangleF(10, 10, 100,
> > 200))

> At this point, the bitmap pointed to by "image" should have the text on
> it and you can directly save the "image" object. No need to create a
> second bitmap.

Really? I thought .net always used ByVal by default and not ByRef. That
would mean that the image is being modfied as a side effect of methods on a
graphic object created from it. Is that right?

If it is then all I need to do is stream my original (but changed) image
back to a Byte array and I'll be able to store it in SQl as before.

I'll be very happy.

I'll let you know how I get on. Thanks for the help.

The reason I was creating a second bitmap is that I need the image in the
form of a Byte array (so I can then load it into a SQL binary field).

I couldn't go direct from a Graphics object to a Byte array (can I?) so I
loaded the graphic into a Bitmap and then saved it to a Stream and converted
the Stream into a Byte array.

I know its a kludge, and I'm sure there's a very neat and streamlined way to
do what I want, but my limited knowledge of the tools means I need help.

' I can convert a Stream to a byte array and that's what
' I need to output. I can convert a Bitmap into a Stream, so...
' Create a Bitmap of the correct width and
' height using my Graphics object image
imgOutput = New Bitmap(image.Width, image.Height, graphic)
' Prepare a new Stream
imgStream = New MemoryStream
' Send the Bitmap down the Stream
imgOutput.Save(imgStream, image.RawFormat)
' Prepare the Byte array to take the stream data
ReDim imgbin(imgStream.Length)
' Set the pointer to the start of the stream
imgStream.Position = 0
' Stream the Bitmap data into the Byte array
n = imgStream.Read(imgbin, 0, imgbin.Length)

Brian Lowe
---------@