T
TheGanjaMan
Hi everyone,
I'm trying to write up a simple image stamper application that stamps the
Exif date information from the jpegs that I've taken from my digital
camera and saves the new file with the date stamped on the lower right
part of the picture. (I'm not an advanced programmer so my code may not
be 100% efficient - sorry, I'm still learning)
Everything works fine until the saving part. I've been able to read the
file into a picturebox, transform it into bitmap to write the text on it,
Then save the file under a new filename.
But when I save the file all Exif information is lost. How can I
preserve this information? I'm thinking that when I transform the image
to a bitmap this loss happens, but When I work on the image itself using
the image.fromfile property the file is locked until the application
exits so I have to read the file as a filestream and convert it into a
bitmap to write text on it and save it without locking the file.
Otherwise I cannot overwrite the file.
I'm doing something along these lines:
(I have 2 pictureboxes pb_orig and pb_final, the Pictext is the Exif date
that is returned from another function)
Dim fs As New System.IO.FileStream(PicName, IO.FileMode.Open)
Dim bm As New Bitmap(fs)
Dim g As Graphics = Graphics.FromImage(bm)
Dim ph As Integer = pb_Orig.Image.Height
Dim pw As Integer = pb_Orig.Image.Width
Dim StrWidth = g.MeasureString(PicText.ToString, New Font
(TS_CB_Font.SelectedText, (pw * 0.05), FontStyle.Regular,
GraphicsUnit.Pixel)).Width
Dim StrHeight = g.MeasureString(PicText.ToString, New Font
(TS_CB_Font.SelectedText, (ph * 0.05), FontStyle.Regular,
GraphicsUnit.Pixel)).Height
g.DrawString(PicText, New Font(TS_CB_Font.Text, (ph * 0.05),
FontStyle.Regular, GraphicsUnit.Pixel), New SolidBrush(CD1.Color),
pb_Orig.Image.Width - StrWidth, pb_Orig.Image.Height - StrHeight)
pb_Final.Image = DirectCast(bm.Clone, Image)
fs.Close()
bm.Dispose()
The save goes like this:
Dim SaveBitmap As New Bitmap(pb_Final.Image)
SaveBitmap.Save(SaveFileDialog1.FileName, Imaging.ImageFormat.Jpeg)
SaveBitmap.Dispose()
If I dont use the Imaging.ImageFormat.Jpeg somehow my pictures end up
being saved as PNG files...
Any help will be greatly appreciated...
I'm trying to write up a simple image stamper application that stamps the
Exif date information from the jpegs that I've taken from my digital
camera and saves the new file with the date stamped on the lower right
part of the picture. (I'm not an advanced programmer so my code may not
be 100% efficient - sorry, I'm still learning)
Everything works fine until the saving part. I've been able to read the
file into a picturebox, transform it into bitmap to write the text on it,
Then save the file under a new filename.
But when I save the file all Exif information is lost. How can I
preserve this information? I'm thinking that when I transform the image
to a bitmap this loss happens, but When I work on the image itself using
the image.fromfile property the file is locked until the application
exits so I have to read the file as a filestream and convert it into a
bitmap to write text on it and save it without locking the file.
Otherwise I cannot overwrite the file.
I'm doing something along these lines:
(I have 2 pictureboxes pb_orig and pb_final, the Pictext is the Exif date
that is returned from another function)
Dim fs As New System.IO.FileStream(PicName, IO.FileMode.Open)
Dim bm As New Bitmap(fs)
Dim g As Graphics = Graphics.FromImage(bm)
Dim ph As Integer = pb_Orig.Image.Height
Dim pw As Integer = pb_Orig.Image.Width
Dim StrWidth = g.MeasureString(PicText.ToString, New Font
(TS_CB_Font.SelectedText, (pw * 0.05), FontStyle.Regular,
GraphicsUnit.Pixel)).Width
Dim StrHeight = g.MeasureString(PicText.ToString, New Font
(TS_CB_Font.SelectedText, (ph * 0.05), FontStyle.Regular,
GraphicsUnit.Pixel)).Height
g.DrawString(PicText, New Font(TS_CB_Font.Text, (ph * 0.05),
FontStyle.Regular, GraphicsUnit.Pixel), New SolidBrush(CD1.Color),
pb_Orig.Image.Width - StrWidth, pb_Orig.Image.Height - StrHeight)
pb_Final.Image = DirectCast(bm.Clone, Image)
fs.Close()
bm.Dispose()
The save goes like this:
Dim SaveBitmap As New Bitmap(pb_Final.Image)
SaveBitmap.Save(SaveFileDialog1.FileName, Imaging.ImageFormat.Jpeg)
SaveBitmap.Dispose()
If I dont use the Imaging.ImageFormat.Jpeg somehow my pictures end up
being saved as PNG files...
Any help will be greatly appreciated...