本文介绍了将字符串转换为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
信用卡终端返回捕获的签名的字符串,但我无法将其转换为图像。我粘贴的代码给出了一个空白图像
我尝试过:
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;
}
推荐答案
这篇关于将字符串转换为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!