jpbivona
asked on
Decode hex text file into viewable bitmap image
I have an output text file with a hex sting, which is the result of capturing a signature image.
Does anyone have any insight as to how I can convert this file into a viewable Bitmap image file?
VB.net
Thanks.
Does anyone have any insight as to how I can convert this file into a viewable Bitmap image file?
VB.net
Thanks.
ASKER
Getting Syntax error: Return Image.FromStream(ms)
'FromStream' is not a member of 'Imaging'
'FromStream' is not a member of 'Imaging'
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Here is my VS About, I have - Imports System.Drawing
Squiggly Blue Line
on
Return Image.FromStream(ms)
in
Base64StringToImage()
Microsoft Visual Studio 2005
Version 8.0.50727.762 (SP.050727-7600)
Microsoft .NET Framework
Version 2.0.50727
Installed Edition: Professional
Microsoft Visual Basic 2005 77626-009-1281673-41223
Microsoft Visual Basic 2005
Microsoft Visual C# 2005 77626-009-1281673-41223
Microsoft Visual C# 2005
Microsoft Visual C++ 2005 77626-009-1281673-41223
Microsoft Visual C++ 2005
Microsoft Visual J# 2005 77626-009-1281673-41223
Microsoft Visual J# 2005
Microsoft Visual Web Developer 2005 77626-009-1281673-41223
Microsoft Visual Web Developer 2005
Microsoft Web Application Projects 2005 77626-009-1281673-41223
Microsoft Web Application Projects 2005
Version 8.0.50727.762
Crystal Reports AAC60-G0CSA4B-V7000AY
Crystal Reports for Visual Studio 2005
Microsoft Visual Studio 2005 Professional Edition - ENU Service Pack 1 (KB926601)
This service pack is for Microsoft Visual Studio 2005 Professional Edition - ENU.
If you later install a more recent service pack, this service pack will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/926601
SQL Server Analysis Services
Microsoft SQL Server Analysis Services Designer
Version 9.00.1399.00
SQL Server Integration Services
Microsoft SQL Server Integration Services Designer
Version 9.00.1399.00
SQL Server Reporting Services
Microsoft SQL Server Reporting Services Designers
Version 9.00.1399.00
Squiggly Blue Line
on
Return Image.FromStream(ms)
in
Base64StringToImage()
Microsoft Visual Studio 2005
Version 8.0.50727.762 (SP.050727-7600)
Microsoft .NET Framework
Version 2.0.50727
Installed Edition: Professional
Microsoft Visual Basic 2005 77626-009-1281673-41223
Microsoft Visual Basic 2005
Microsoft Visual C# 2005 77626-009-1281673-41223
Microsoft Visual C# 2005
Microsoft Visual C++ 2005 77626-009-1281673-41223
Microsoft Visual C++ 2005
Microsoft Visual J# 2005 77626-009-1281673-41223
Microsoft Visual J# 2005
Microsoft Visual Web Developer 2005 77626-009-1281673-41223
Microsoft Visual Web Developer 2005
Microsoft Web Application Projects 2005 77626-009-1281673-41223
Microsoft Web Application Projects 2005
Version 8.0.50727.762
Crystal Reports AAC60-G0CSA4B-V7000AY
Crystal Reports for Visual Studio 2005
Microsoft Visual Studio 2005 Professional Edition - ENU Service Pack 1 (KB926601)
This service pack is for Microsoft Visual Studio 2005 Professional Edition - ENU.
If you later install a more recent service pack, this service pack will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/926601
SQL Server Analysis Services
Microsoft SQL Server Analysis Services Designer
Version 9.00.1399.00
SQL Server Integration Services
Microsoft SQL Server Integration Services Designer
Version 9.00.1399.00
SQL Server Reporting Services
Microsoft SQL Server Reporting Services Designers
Version 9.00.1399.00
ASKER
I find this very strange......I see example of using Image.FromStream()....but I have a syntax error even though I have 'Imports System.Drawing'
This seems kinda bad??
This seems kinda bad??
Ok, well try some fully-qualified references:
Public Class ImageConverter
Public Shared Function ByteArrayToImage(ByVal data() As Byte, ByVal fileName As String) As Image
Using ms As New System.IO.MemoryStream(Dat a)
Dim img As Image = System.Drawing.Image.FromS tream(ms)
Return img
End Using
End Function
Public Shared Function ImageToByteArray(ByVal img As System.Drawing.Image, ByVal format As System.Drawing.Imaging.Ima geFormat) As Byte()
Using ms As New System.IO.MemoryStream()
img.Save(ms, format)
Return ms.ToArray()
End Using
End Function
Public Shared Function ImageToBase64String(ByVal img As System.Drawing.Image, ByVal format As System.Drawing.Imaging.Ima geFormat) As String
Using ms As New System.IO.MemoryStream()
img.Save(ms, format)
Return Convert.ToBase64String(ms. ToArray())
End Using
End Function
Public Shared Function Base64StringToImage(ByVal imageString As String) As System.Drawing.Image
Dim data() As Byte = Convert.FromBase64String(i mageString )
Using ms As New System.IO.MemoryStream(dat a)
Return System.Drawing.Image.FromS tream(ms)
End Using
End Function
End Class
Bob
Public Class ImageConverter
Public Shared Function ByteArrayToImage(ByVal data() As Byte, ByVal fileName As String) As Image
Using ms As New System.IO.MemoryStream(Dat
Dim img As Image = System.Drawing.Image.FromS
Return img
End Using
End Function
Public Shared Function ImageToByteArray(ByVal img As System.Drawing.Image, ByVal format As System.Drawing.Imaging.Ima
Using ms As New System.IO.MemoryStream()
img.Save(ms, format)
Return ms.ToArray()
End Using
End Function
Public Shared Function ImageToBase64String(ByVal img As System.Drawing.Image, ByVal format As System.Drawing.Imaging.Ima
Using ms As New System.IO.MemoryStream()
img.Save(ms, format)
Return Convert.ToBase64String(ms.
End Using
End Function
Public Shared Function Base64StringToImage(ByVal imageString As String) As System.Drawing.Image
Dim data() As Byte = Convert.FromBase64String(i
Using ms As New System.IO.MemoryStream(dat
Return System.Drawing.Image.FromS
End Using
End Function
End Class
Bob
ASKER
Well, it seems the problem was that with a mobile device application, FromStream() in not a part of the .NET CF.
Oh well.
Oh well.
Hi,
does anybody know how to perform the same task in Delphi?
I also have an output text file with a hex sting, which is the result of capturing a signature image.
The string looks like below:
PRY7FTcUNBQyFjEYMhozHDYcNx 84ITYjMyQx JS8kLSQtJP //QxJCFEIW QhlBG0EdQR 9BIUMfQx// /1YOVhBUD1 IQUBBNEUwT SxZMGE0aTx xRHFMeVR9X HlgbWBlWGF MYURhPGE8Y //9gGl8YXx ZfFF8SYBBg DmIPYxFkFG UXZhloFmgU aRFqDmoMag pqCv//Rz1H P0dBR
here is what the PDA vendor says about the file:
-------------------------- ---------- ---------- ---------- ---------
Ok, the data coming in is basically a list of lines to draw.
To make the data in the first place, a series of points that would create the lines of the signature are recorded, where any pen lift (i.e. the drawing stopped) is recorded as 255,255 to serve as a terminator.
This array of points is turned into a byte array (i.e. line from 2,3 to 40, 50 to 80, 3 becomes byte[] {2,3,40,50, 80, 3} )
This is run through a Microsoft call Convert.ToBase64String to cut down on size (ever seen how big an xml encoded byte array is?) and make it easier to pass the data back into a webservice via a string parameter. The data will need to be de-converted from this form to get the byte array back out, that is then used to draw the lines in the code sample you supplied.
-------------------------- ---------- ---------- ---------- ---------
How to convert this file back into a viewable Bitmap image file?
thanks
Anthony
does anybody know how to perform the same task in Delphi?
I also have an output text file with a hex sting, which is the result of capturing a signature image.
The string looks like below:
PRY7FTcUNBQyFjEYMhozHDYcNx
here is what the PDA vendor says about the file:
--------------------------
Ok, the data coming in is basically a list of lines to draw.
To make the data in the first place, a series of points that would create the lines of the signature are recorded, where any pen lift (i.e. the drawing stopped) is recorded as 255,255 to serve as a terminator.
This array of points is turned into a byte array (i.e. line from 2,3 to 40, 50 to 80, 3 becomes byte[] {2,3,40,50, 80, 3} )
This is run through a Microsoft call Convert.ToBase64String to cut down on size (ever seen how big an xml encoded byte array is?) and make it easier to pass the data back into a webservice via a string parameter. The data will need to be de-converted from this form to get the byte array back out, that is then used to draw the lines in the code sample you supplied.
--------------------------
How to convert this file back into a viewable Bitmap image file?
thanks
Anthony
If so, then you can use something like this:
Imports System.IO
Imports System.Drawing.Imaging
Public Class ImageConverter
Public Shared Function ByteArrayToImage(ByVal buffer() As Byte, ByVal fileName As String) As Image
Using ms As New MemoryStream(buffer)
Dim img As Image = Image.FromStream(ms)
Return img
End Using
End Function
Public Shared Function ImageToByteArray(ByVal img As Image, ByVal format As ImageFormat) As Byte()
Using ms As New MemoryStream()
img.Save(ms, format)
Return ms.ToArray()
End Using
End Function
Public Shared Function ImageToBase64String(ByVal img As Image, ByVal format As ImageFormat) As String
Using ms As New MemoryStream()
img.Save(ms, format)
Return Convert.ToBase64String(ms.
End Using
End Function
Public Shared Function Base64StringToImage(ByVal imageString As String) As Image
Dim buffer() As Byte = Convert.FromBase64String(i
Using ms As New MemoryStream(buffer)
Return Image.FromStream(ms)
End Using
End Function
End Class
Bob