只是想知道是否有人知道如何将 bmp 字节数组转换为实际图像?
图片摘录 :
424d 4284 0300 0000 0000 4200 0000 2800
0000 4001 0000 f000 0000 0100 1800 0300
这不适用于 bmp(其中数据是代表图像的输入字符串)
$im = imagecreatefromstring($data);
if ($im !== false) {
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
}
else {
echo 'An error occurred.';
}
谢谢!
似乎 imagecreatefromstring() 或 PHP 的 GD 不支持 BMP [1]
它似乎支持 WBMP,而不是 BMP。[2]
此外,imagecreatefromstring() 希望接收整个文件,而不仅仅是您可能拥有的任何选定像素的"提取"。如果它接受原始像素数据(忘记颜色格式、位计数等问题),您仍然需要至少为 imagecreatefromstring() 指定每行像素,以便 GD 构成您的"原始数据"的任何内容。
由于 BMP 的性质,其中数据是未压缩的像素数据,如果您真的需要,我想您可以 imagecreate() 一个空图像并在 for (y) { for (x) { ... } } 循环中使用 imagesetpixel() 来设置来自原始 BMP 文件提取的像素数据。不知道你想做什么,我仍然敢打赌会有更简单的方法。
[1] http://php.net/manual/en/function.imagecreatefromstring.php/"imagecreatefromstring() 返回一个图像标识符,表示从给定图像获得的图像。如果你的PHP版本支持这些类型,它们将被自动检测:JPEG,PNG,GIF,WBMP和GD2。
[2] http://en.wikipedia.org/wiki/Wireless_Application_Protocol_Bitmap_Format