Home  >  Article  >  Backend Development  >  请问如何将字节数组转换成图片?

请问如何将字节数组转换成图片?

不言
不言Original
2018-05-28 11:44:533684browse

     var data = "255,216,255,224,0,16,74,70,73,70,0,1,180,16,71,23,134,180,248,126,198,211,174,90,72,25,98,223,27,2,170,65,13,156,170,156,241,69,21,124,145,229,90,117,48,73,28,135,133,252,79,226,157,30,194,24,116,191,17,92,105,118,111,111,253,146,97,179,13,17,91,68,148,76,170,165,88,5,112,197,212,62,50,35,145,148,14,140,59,79,135,11,175,191,132,163,211,52,221,116,88,104,182,145,93,91,90,89,188,14,242,65,20,247,13,113,46,46,18,68,152,185,119,35,37,246,149,0,50,55,36,148,85,212,163,78,223,9,164,86,167,57,225,95,17,248,171,91,186,214,180,246,215,98,142,45,107,87,184,215,238,75,89,43,149,191,184,72,209,231,66,91,42,200,16,24,249,249,88,146,219,248,2,238,143,225,155,212,142,72,226,215,46,236,117,25,224,136,195,169,105,228,219,207,106,233,7,217,225,120,217,91,33,146,56,192,206,121,201,232,14,40,162,176,132,35,103,161,15,245,59,127,25,234,94,37,241,119,140,52,155,189,114,251,71,70,182,154,93,77,99,209,116,183,180,89,39,158,72,196,143,38,249,229,44,113,8,0,228,99,123,231,57,24,40,162,185,161,8,219,97,180,174,127,255,217";            
     var arr = data.Split(",".ToCharArray());            
     var img_bytes = new byte[arr.Length];           
     var pos = 0;            
     foreach (var s in arr)            
     {                
     img_bytes[pos] = Convert.ToByte(s);                
     ++pos;            
     }            
     var MS = new MemoryStream(img_bytes);            
     Bitmap image = new System.Drawing.Bitmap(MS);            
     this.pictureBox1.Image = image;

上边是c#的代码。但我不知道php里有没类似的。 上边的字节数据没发完。因为太长了。  
我把请求出来的图片存放成字节数组,请问php中有没有方法将一个字节数组转换回图片?

回复讨论(解决方案)

$data = "255,216,255,224,0,16,74,70,73,70,0,1,180,16,71,23,134,180,248,126,198,211,174,90,72,25,98,223,27,2,170,65,13,156,170,156,241,69,21,124,145,229,90,117,48,73,28,135,133,252,79,226,157,30,194,24,116,191,17,92,105,118,111,111,253,146,97,179,13,17,91,68,148,76,170,165,88,5,112,197,212,62,50,35,145,148,14,140,59,79,135,11,175,191,132,163,211,52,221,116,88,104,182,145,93,91,90,89,188,14,242,65,20,247,13,113,46,46,18,68,152,185,119,35,37,246,149,0,50,55,36,148,85,212,163,78,223,9,164,86,167,57,225,95,17,248,171,91,186,214,180,246,215,98,142,45,107,87,184,215,238,75,89,43,149,191,184,72,209,231,66,91,42,200,16,24,249,249,88,146,219,248,2,238,143,225,155,212,142,72,226,215,46,236,117,25,224,136,195,169,105,228,219,207,106,233,7,217,225,120,217,91,33,146,56,192,206,121,201,232,14,40,162,176,132,35,103,161,15,245,59,127,25,234,94,37,241,119,140,52,155,189,114,251,71,70,182,154,93,77,99,209,116,183,180,89,39,158,72,196,143,38,249,229,44,113,8,0,228,99,123,231,57,24,40,162,185,161,8,219,97,180,174,127,255,217";
$a = explode(',', $data);
file_put_contents('a.jfif', join('', array_map('chr', $a)));

你最好把数据弄全了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn