Home All Groups Group Topic Archive Search About

Adding text to a jpeg file

Author
16 Jun 2006 5:51 AM
Jerry Spence1
I am trying to add the date/time to a jpg file. I came across the following
on the web which looks ideal. However, my experiences in this direction are
nil!

How do I modify the first line(s) to get the image from a file into bmap?

Thanks

-Jerry

Dim bmap As Image
'pull an image from memory, could also be from the file system.
bmap = CType(Data.GetData(GetType(System.Drawing.Bitmap)), Image)
'here's where we modify the image in memory
Dim g As Graphics = Graphics.FromImage(bmap)
'now prepare our brush to draw the text onto the image.
Dim drawFont As New Font("Arial", 10, FontStyle.Bold,
GraphicsUnit.Millimeter)
Dim drawBrush As New SolidBrush(Color.Red)
'figure out where we want to place the text getting the x & y coordinate.
Dim xPos As Integer = bmap.Height - (bmap.Height - 25)
Dim yPos As Integer = 3
'now draw the date using "Now".
g.DrawString(Now, drawFont, drawBrush, xPos, yPos)
'check to see if the property to save the file is enabled.


Now that we have a modified image in memory we can save the file to disk and
generate a thumbnail image as well to present in the Web page for later
viewing.

Dim sPicPath As String = "C:\Path to your file store\filename.jpg"
Dim sPreFix As String = "C:\image file path\"
'now declare another image to store our thumbnail image.
Dim smBmap As Image
'now we're going to get a thumbnail image from the bitmap we worked
'with earlier in the method.
smBmap = bmap.GetThumbnailImage(bmap.Width, bmap.Height, Nothing, Nothing)
'save the image to our path and save it as a jpeg.
smBmap.Save(sPicPath, Imaging.ImageFormat.Jpeg)
'now save a copy of the original image to the local disk.
bmap.Save(Replace(sPreFix, "\images", "") & ".jpg",
Imaging.ImageFormat.Jpeg)
bmap = Nothing
smBmap = Nothing

Author
16 Jun 2006 6:20 AM
Peter Proost
Hi,

dim bmap as New Bitmap("c:\youfilepath_and_name")

www.bobpowell.net is a very good site for information on drawing with .net
but it seems to be down for the moment, but it's a very helpful site

Hope this helps,

Peter


--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

Show quoteHide quote
"Jerry Spence1" <jerry.spe***@somewhere.com> schreef in bericht
news:449246da$0$3512$ed2619ec@ptn-nntp-reader01.plus.net...
> I am trying to add the date/time to a jpg file. I came across the
following
> on the web which looks ideal. However, my experiences in this direction
are
> nil!
>
> How do I modify the first line(s) to get the image from a file into bmap?
>
> Thanks
>
> -Jerry
>
> Dim bmap As Image
> 'pull an image from memory, could also be from the file system.
> bmap = CType(Data.GetData(GetType(System.Drawing.Bitmap)), Image)
> 'here's where we modify the image in memory
> Dim g As Graphics = Graphics.FromImage(bmap)
> 'now prepare our brush to draw the text onto the image.
> Dim drawFont As New Font("Arial", 10, FontStyle.Bold,
> GraphicsUnit.Millimeter)
> Dim drawBrush As New SolidBrush(Color.Red)
> 'figure out where we want to place the text getting the x & y coordinate.
> Dim xPos As Integer = bmap.Height - (bmap.Height - 25)
> Dim yPos As Integer = 3
> 'now draw the date using "Now".
> g.DrawString(Now, drawFont, drawBrush, xPos, yPos)
> 'check to see if the property to save the file is enabled.
>
>
> Now that we have a modified image in memory we can save the file to disk
and
> generate a thumbnail image as well to present in the Web page for later
> viewing.
>
> Dim sPicPath As String = "C:\Path to your file store\filename.jpg"
> Dim sPreFix As String = "C:\image file path\"
> 'now declare another image to store our thumbnail image.
> Dim smBmap As Image
> 'now we're going to get a thumbnail image from the bitmap we worked
> 'with earlier in the method.
> smBmap = bmap.GetThumbnailImage(bmap.Width, bmap.Height, Nothing, Nothing)
> 'save the image to our path and save it as a jpeg.
> smBmap.Save(sPicPath, Imaging.ImageFormat.Jpeg)
> 'now save a copy of the original image to the local disk.
> bmap.Save(Replace(sPreFix, "\images", "") & ".jpg",
> Imaging.ImageFormat.Jpeg)
> bmap = Nothing
> smBmap = Nothing
>
>