Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, Credit Card terminal returns a string for the signature captured but I am not able convert it to image. The code that I have pasted gives a blank image

What I have tried:

string signature = "0,65535^49,10^45,13^43,17^41,21^39,25^37,29^36,33^34,37^33,41^32,45^31,49^30,54^30,58^31,62^34,66^38,67^42,67^46,65^50,63^54,60^58,57^63,53^67,48^71,44^75,40^79,36^83,32^87,28^91,25^95,23^95,27^94,31^92,35^91,39^90,43^88,47^86,52^85,56^84,60^83,64^82,68^82,72^84,76^88,78^92,77^96,76^100,73^104,71^108,68^112,66^116,62^121,60^125,59^129,58^133,58^137,60^140,64^141,68^142,72^143,76^145,80^149,83^153,85^157,85^161,86^165,85^169,85^173,85^177,84^182,83^186,83^190,81^";

           char[] charArr = signature.ToCharArray();

           byte[] array = Encoding.GetEncoding("UTF-8").GetBytes(charArr);

           var im = ImageFromRawBgraArray(array, 1000, 1000);


 public System.Drawing.Image ImageFromRawBgraArray(byte[] arr, int width, int height)
       {
           var output = new System.Drawing.Bitmap(width, height);
           var rect = new System.Drawing.Rectangle(0, 0, width, height);
           var bmpData = output.LockBits(rect,
               System.Drawing.Imaging.ImageLockMode.ReadWrite, output.PixelFormat);
           var ptr = bmpData.Scan0;
           System.Runtime.InteropServices.Marshal.Copy(arr, 0, ptr, arr.Length);
           output.UnlockBits(bmpData);
           return output;
       }
Posted
Updated 12-May-17 22:41pm

1 solution

First off, that string isn't an image, and converting it to bytes doesn't help that - you are converting each character in the string to a bytes, which in fact just leaves all those values unchanged as they are all in the range '0' to '9' plus two other characters ',' and '^'.

You need to go back to wherever you got the information on what that data is and read it again: it's possible there is an image in there, but it isn't in a "ready to display" format and will need a fair amount of processing in order to convert it into a format you can use. Until you know what format that data is, and how it is encoded, it's useless to you (and possibly encrypted as well given this is credit card info).
 
Share this answer
 
Comments
Qadeer Ahmed Khan 13-May-17 5:04am    
So I found this in documentation.

Note:
The value of vector coordinates delimited with a ^ character in the following format: x1,y1^x2,y2^xN,yN^~
If there is a pen-up event, then you use the coordinate 0, 65535 to signal a break in the line
^ is the coordinate delimiter, ~ is the ending delimiter, and a comma (,) is the vector delimiter
OriginalGriff 13-May-17 5:12am    
And there is your answer: it's not an image, it's a set of vector coordinates you will need to process and draw onto an image, not image data in itself.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900