请问如何将字节数组转换成图片?
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)));
你最好把数据弄全了

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The method of using a foreach loop to remove duplicate elements from a PHP array is as follows: traverse the array, and if the element already exists and the current position is not the first occurrence, delete it. For example, if there are duplicate records in the database query results, you can use this method to remove them and obtain results without duplicate records.

The performance comparison of PHP array key value flipping methods shows that the array_flip() function performs better than the for loop in large arrays (more than 1 million elements) and takes less time. The for loop method of manually flipping key values takes a relatively long time.

Methods for deep copying arrays in PHP include: JSON encoding and decoding using json_decode and json_encode. Use array_map and clone to make deep copies of keys and values. Use serialize and unserialize for serialization and deserialization.

Multidimensional array sorting can be divided into single column sorting and nested sorting. Single column sorting can use the array_multisort() function to sort by columns; nested sorting requires a recursive function to traverse the array and sort it. Practical cases include sorting by product name and compound sorting by sales volume and price.

PHP's array_group_by function can group elements in an array based on keys or closure functions, returning an associative array where the key is the group name and the value is an array of elements belonging to the group.

The best practice for performing an array deep copy in PHP is to use json_decode(json_encode($arr)) to convert the array to a JSON string and then convert it back to an array. Use unserialize(serialize($arr)) to serialize the array to a string and then deserialize it to a new array. Use the RecursiveIteratorIterator to recursively traverse multidimensional arrays.

Complexity of PHP array deduplication algorithm: array_unique(): O(n) array_flip()+array_keys(): O(n) foreach loop: O(n^2)

Documents in PDF format are widely used in various fields, in the digital age, but sometimes we need to convert them to JPG image format to meet specific needs. As well as solutions to common problems, this article will introduce in detail how to use practical tools to convert PDF files into high-quality, lossless JPG images. Choose the appropriate PDF to JPG conversion tool as well as its characteristics and applicable scenarios, desktop software and mobile applications, and introduce several common PDF to JPG conversion tools, including online conversion. An introduction to online converters such as Adobe Acrobat Online, including operating steps, detailed introduction to common online converters, Smallpdf, Zamzar, etc., upload restrictions and conversion quality, etc. Desktop software recommendations and usage Ni
