Images

G

Guest

We are having an odd problem saving images. We capture customer signatures
on a Palm Pilot and save them as points on a graph. We are able to
reconstruct these points to display the signature, but when we attempt to
save the file off so that we can pass it back to our customers we get an odd
result. If we try to view the file using Windows Picture and Fax viewer,
everything's ok. But try to view it using any other graphics program (such
as Paint or even as thumbnails in Windows Explorer) and we get nothing but a
black box. I have another app (JASC Image Commander) that tells me that the
file is not a valid JPG or BMP file (we tried both). Here's a sample of the
code.

SignatureManager is a DLL that is used to plot the points and reconstruct
the image. As I said, it displays just fine in the Picture Box on the form.

Dim SigMan As ASTSignature.SignatureManager
picSignature.SizeMode = PictureBoxSizeMode.StretchImage

Dim imgSignature As New System.Drawing.Bitmap(320, 138,
Imaging.PixelFormat.Format32bppArgb)
imgSignature = CType(SigMan.GetSignature(CStr(iDSID)),
Bitmap)

picSignature.Image = imgSignature
picSignature.ClientSize = New Size(208, 72)

imgSignature.Save(sFileName)

Anyone have any thoughts?
 
B

Barry

Hi, EdB,

When you save, you should specify what format you are going to save
to....

imgSignature.Save(sFileName, System.Drawing.Imaging.ImageFormat.jpeg)
or
imgSignature.Save(sFileName, System.Drawing.Imaging.ImageFormat.bmp)

then see if you can open it.

HTH,
Barry

We are having an odd problem saving images. We capture customer signatures
on a Palm Pilot and save them as points on a graph. We are able to
reconstruct these points to display the signature, but when we attempt to
save the file off so that we can pass it back to our customers we get an odd
result. If we try to view the file using Windows Picture and Fax viewer,
everything's ok. But try to view it using any other graphics program (such
as Paint or even as thumbnails in Windows Explorer) and we get nothing but a
black box. I have another app (JASC Image Commander) that tells me that the
file is not a valid JPG or BMP file (we tried both). Here's a sample of the
code.

SignatureManager is a DLL that is used to plot the points and reconstruct
the image. As I said, it displays just fine in the Picture Box on the form.

Dim SigMan As ASTSignature.SignatureManager
picSignature.SizeMode = PictureBoxSizeMode.StretchImage

Dim imgSignature As New System.Drawing.Bitmap(320, 138,
Imaging.PixelFormat.Format32bppArgb)
imgSignature = CType(SigMan.GetSignature(CStr(iDSID)),
Bitmap)

picSignature.Image = imgSignature
picSignature.ClientSize = New Size(208, 72)

imgSignature.Save(sFileName)

Anyone have any thoughts?

bceggersATcomcastDOTnet
 
G

Guest

Thanks, but that did not make a difference. I had had that in there, put it
back as you suggested and it didn't help. Infact, now even the Windows
Picture and Fax Viewer doesn't recognize it.
 
L

Larry Serflaten

EdB said:
We are having an odd problem saving images.
Dim imgSignature As New System.Drawing.Bitmap(320, 138, Imaging.PixelFormat.Format32bppArgb)
imgSignature = CType(SigMan.GetSignature(CStr(iDSID)), Bitmap)

picSignature.Image = imgSignature

Anyone have any thoughts?


It seems a bit strange that you would create a bitmap, asign it to a variable, and
then assign a different bitmap to that same variable. I would have thought that
section should look more like:

Dim imgSignature As Bitmap = CType(SigMan.GetSignature(CStr(iDSID)), Bitmap)
picSignature.Image = imgSignature.Clone


None the less, see if using the Clone method will help....

LFS
 
B

Bob Powell [MVP]

When creating a new 32bpp image the default values in the pixel array are
transparent black. This is interpreted in the picturebox as fully
transparent so you're probably seeing the signature just fine because its
projected over the back-colour of the picturebox. When this is saved all the
image transparency will be lost unless you save to PNG so you'll just see
what is apparently a black image..

Try setting the bitmap to white when you create it like this:
Dim imgSignature As New System.Drawing.Bitmap(320, 138,
Imaging.PixelFormat.Format32bppArgb)
Dim g as Graphics.FromImage(imgSignature)
g.Clear(Color.White)
g.Dispose()

'continue with the rest of your stuff here...





--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
G

Guest

Larry,

Thanks for the reply, but I still get "Invalid Bitmap" on the resulting files.
 
G

Guest

Bob,

Thanks for the response.

When I tried this I got a compile error on this line:

Dim g as Graphics.FromImage(imgSignature)

The error says:

Array Bounds Cannot Appear In Type Specifiers
 
L

Larry Serflaten

EdB said:
Larry,

Thanks for the reply, but I still get "Invalid Bitmap" on the resulting files.

If you've tried declaring the format when you save, and you've tried using
a clone, I'd suggest the next thing is to try to copy the image from your
picturebox to another bitmap.

If you can copy it to another bitmap, you certainly should be able to save it.

Something is amiss, unfortunately you are the one who has to find it... :p

LFS
 
G

Guest

I figured this out. This

Dim g as Graphics.FromImage(imgSignature)

needs to be

Dim g as Graphics = Graphics.FromImage(imgSignature)

But still, no joy.
 
B

Bob Powell [MVP]

Do you mean no joy as in the image is still black? There must be something
weird going on. Can you post a more comprehensive chunk of code?

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
G

Guest

Ask and you shall receive:


#Step 1 - obtain Record ID
Dim iDSID As Int32 = DailyStop.GetDailyStopID(sLocationID, strSigTerminal,
strPullDate, strSigTime)
#Step 2 - Create resulting file name
Dim sFileName As String = "D:\CardinalSigs\" & CStr(iDSID) & ".bmp"

Try
#Step 3 - Signatures are based on locations, could be multiple
# packages per location, only gen the signature once
h.Add(CStr(iDSID), iDSID)

#Step 4 - Declare SigMan

Dim SigMan As ASTSignature.SignatureManager

picSignature.SizeMode = PictureBoxSizeMode.StretchImage

Dim imgSignature As New System.Drawing.Bitmap(320, 138,
Imaging.PixelFormat.Format32bppArgb)
Dim g As Graphics = Graphics.FromImage(imgSignature)
g.Clear(Color.White)
g.Dispose()

#Step 5 = Build the signature (Code below)
imgSignature = CType(SigMan.GetSignature(CStr(iDSID)), Bitmap)

#Step 6 - Assign image (This displays the sig)
picSignature.Image = imgSignature
picSignature.ClientSize = New Size(208, 72)

#Step 7 - Save the image
imgSignature.Save(sFileName)

Catch ex As Exception
'Do Nothing
End Try


#########GET SIGNATURE CODE

Public Shared Function GetSignature(ByVal StopID As String, Optional
ByVal Messages As Boolean = False) As System.Drawing.Image
Dim Result As System.Drawing.Bitmap

Dim ImageForSignatures As System.Drawing.Bitmap
Dim g As System.Drawing.Graphics
Dim blackPen As System.Drawing.Pen = New
System.Drawing.Pen(System.Drawing.Color.Black)

Dim intX As Integer = 0
Dim intY As Integer = 0
Dim intOX As Integer = 0
Dim intOY As Integer = 0
Dim startX As Integer = 1
Dim startY As Integer = 0
Dim lengthX As Integer = 0
Dim lengthY As Integer = 0
Dim nextComma As Integer = 0
Dim rawString As String = ""
Dim intStringLength As Integer = 0
Dim Position As Integer = 0
Try

Dim sqlConnection As New SqlConnection(myConnectionString)
sqlConnection.Open()
Dim sql1 As String = "Select ProcessDate, CourierID,
RouteNumberComplete, StopNumber From DailyStops Where ID = @ID"
Dim sql2 As String = "Select RawPoints From RawSignature Where
CourierID = @CID and Route = @RNC and StopNumber = @Num and ProcessDate = @PD"

Dim PD As DateTime
Dim CID As String = ""
Dim Route As String = ""
Dim Sequence As Integer = 0

Dim dr As SqlDataReader
Dim myCommand As New SqlCommand(sql1, sqlConnection)
myCommand.Parameters.Add("@ID", StopID)
dr = myCommand.ExecuteReader
dr.Read()
myCommand.Parameters.Clear()
PD = dr.GetDateTime(dr.GetOrdinal("ProcessDate"))
CID = dr.GetString(dr.GetOrdinal("CourierID"))
Route = dr.GetString(dr.GetOrdinal("RouteNumberComplete"))
Sequence = dr.GetInt32(dr.GetOrdinal("StopNumber"))
dr.Close()

myCommand.CommandText = sql2
myCommand.Parameters.Add("@RNC", Route)
myCommand.Parameters.Add("@CID", CID)
myCommand.Parameters.Add("@Num", Sequence)
myCommand.Parameters.Add("@PD", PD)
dr = myCommand.ExecuteReader
dr.Read()
blackPen.Width = 2
ImageForSignatures = New System.Drawing.Bitmap(320, 138,
Drawing.Imaging.PixelFormat.Format32bppArgb)
g = g.FromImage(ImageForSignatures)

'Parse the string
rawString = dr.GetString(dr.GetOrdinal("RawPoints"))
intStringLength = rawString.Length

While Position < intStringLength
Try
'startX = 0
nextComma = InStr(startX, rawString, ",")

lengthX = nextComma - startX

intX = CInt(rawString.Substring(startX - 1, lengthX))

startY = nextComma + 1

nextComma = InStr(startY, rawString, ",")
If nextComma = 0 Then
nextComma = rawString.Length + 1
End If
lengthY = nextComma - startY

intY = CInt(rawString.Substring(startY - 1, lengthY))

startX = nextComma + 2

Position = startX

If (intX <> intOX Or intY <> intOY) And (intOX <> 0 And
intOY <> 0) Then
'Draw the points out of the string
DrawPoints(intX, intY, intOX, intOY, blackPen, g)
End If

intOX = intX

intOY = intY

Catch e As Exception
Dim str As String = e.Message
Position = intStringLength + 1
End Try

End While

g.DrawImage(ImageForSignatures, New System.Drawing.Point(0, 0))
Result = ImageForSignatures
ImageForSignatures.Save("D:\CardinalSigs\" + StopID + ".jpg")
g.Dispose()

Catch e As Exception
Result = New Bitmap("D:\Signature\NoSig.jpg")
If Messages Then
Throw e 'MsgBox(e.Message)
End If
End Try

Return Result
End Function
 
B

Bob Powell [MVP]

But you're still saving the file without specifying an image format. Saving
to a filename without specifying saves it in raw format. Use the line...

imgSignature.Save(sFileName,ImageFormat.Jpeg) 'or png or gif or
whatever......


--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
G

Guest

.....and that still yields me a black rectangle.

I really need to figure out if this is a VB.Net bug or something we're
doing. Would you entertain the idea of taking this off line? I would be
willing to pay a fee for your time. I would like to give you access to the
computer that this is being done on and have you look at it directly. Is
that possible?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top