将字符串转换为图像 [英] Convert string to image

查看:124
本文介绍了将字符串转换为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

信用卡终端返回捕获的签名的字符串,但我无法将其转换为图像。我粘贴的代码给出了一个空白图像



我尝试过:



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;
       }

推荐答案

首先,该字符串不是图像,并将其转换为字节你帮忙 - 你将字符串中的每个字符转换成一个字节,实际上只是保留所有这些值,因为它们都在'0'到'9'的范围加上另外两个字符','和'^ '。



您需要回到有关该数据的信息的地方并再次阅读:那里可能有图像,但它不是准备显示格式,需要进行大量处理才能将其转换为您可以使用的格式。在你知道数据的格式以及数据的编码方式之前,它对你来说是无用的(并且可能加密,因为这是信用卡信息)。
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).


这篇关于将字符串转换为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆