php - Imagen、HEX 到 Byte 和 Byte 到 HEX 并显示 img。Visual Basic 到 PHP
问题描述
我必须将 Visual Basic 中的函数传递给 PHP 以读取保存在 MySQL 中的此图像。我已经尝试了几件事,但我没有在当前保存的数据库 MySql 中执行此操作:https ://www.pastiebin.com/5bbba9dbc63f6#&togetherjs=73xi1xwALu
'Save string a Byte in MySql
Public Function StringaByte(cTexto As String) As Byte()
Dim aByte() As Byte
Dim aHexa() As String
Dim i As Long
aHexa = Split(cTexto, "&H")
ReDim aByte(UBound(aHexa) + 1) As Byte
For i = 0 To UBound(aHexa) - 1
DoEvents
aByte(i) = CLng("&H" & aHexa(i + 1))
Next
StringaByte = aByte
End Function
'Load hexa in MySql an conver to Byte
Private Function ByteaString(aByte() As Byte) As String
Dim i As Long
Dim cHex As String
cHex = ""
For i = 0 To UBound(aByte)
DoEvents
cHex = cHex & "&H" & Hex(aByte(i))
Next
ByteaString = cHex
End Function
在 PHP 中我尝试了函数 hex2bin 并打包
<?php
//header("Content-type: image/gif");
header("Content-type: image/jpg");
$img2="CODE HEXA IN LINK";
function hextobin($hexstr){
$aHexa = explode("&H", $hexstr);
$count=count($aHexa);
$aByte="";
for ($x=0;$x<$count; $x++){
@$aByte .="&H".hex2bin($aHexa[$x]);
}
return $aByte;
}
$acomulo= hextobin($img2) ;
echo base64_decode($acomulo);exit;
//echo $acomulo;exit;
?>
php 中的其他示例
<?php
$img2="CODE HEXA IN LINK";
function hextobin($hexstr) {
$aHexa = explode("&H", $hexstr);
$count = count($aHexa);
$aByte = "";
for ($x = 0; $x < $count; $x++) {;
@$aByte .=pack("H*", $aHexa[$x]);
}
return @$aByte;
}
$acomulo = hextobin($img2);
header("Content-type: image/gif");
echo base64_decode($acomulo);
exit;
?>
解决方案
视觉功能不会生成原始的 100% 十六进制。
function vb6toIMG($func_string){
$func_string=substr($func_string,2);
//die($func_string);
$arrayHex=explode ("&H",$func_string);
$str="";
foreach($arrayHex as $ind=>$dato){
$str.=chr(hexdec($dato));
}
return $str;
}
推荐阅读
- css - 元素宽度与最宽的子元素一样宽,并排而不占用全宽
- qt - 自定义抓取物品的图像
- java - 为什么有和没有 ExecutorService 的任务花费相同的时间?
- java - 如何运行 Jenkins 并查看测试的可视化运行
- c# - Raise event in C# and catch in C++ MFC
- postgresql - 迭代插入值
- javascript - 无法重现查询参数 html 注入
- elasticsearch - 如何正确使用 SearchAfter API?
- spring-boot - 如何在 log4j2 配置中使用 Spring Boot application.yml 属性?
- c# - 如何使用序列化的二进制文件创建高分