Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial 请问如何将字节数组转换成图片?

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

May 28, 2018 am 11:44 AM
picture byte array converted to

     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;
Copy after login

上边是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)));
Copy after login

你最好把数据弄全了

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1669
14
PHP Tutorial
1273
29
C# Tutorial
1256
24
How to remove duplicate elements from PHP array using foreach loop? How to remove duplicate elements from PHP array using foreach loop? Apr 27, 2024 am 11:33 AM

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.

PHP array key value flipping: Comparative performance analysis of different methods PHP array key value flipping: Comparative performance analysis of different methods May 03, 2024 pm 09:03 PM

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.

The Art of PHP Array Deep Copy: Using Different Methods to Achieve a Perfect Copy The Art of PHP Array Deep Copy: Using Different Methods to Achieve a Perfect Copy May 01, 2024 pm 12:30 PM

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.

PHP array multi-dimensional sorting practice: from simple to complex scenarios PHP array multi-dimensional sorting practice: from simple to complex scenarios Apr 29, 2024 pm 09:12 PM

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.

Application of PHP array grouping function in data sorting Application of PHP array grouping function in data sorting May 04, 2024 pm 01:03 PM

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.

Best Practices for Deep Copying PHP Arrays: Discover Efficient Methods Best Practices for Deep Copying PHP Arrays: Discover Efficient Methods Apr 30, 2024 pm 03:42 PM

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.

Exploring the complexity of PHP array deduplication algorithms Exploring the complexity of PHP array deduplication algorithms Apr 28, 2024 pm 05:54 PM

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

Convert PDF to JPG format (fast) Convert PDF to JPG format (fast) Apr 19, 2024 am 08:13 AM

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

See all articles