如图所示,已知假设所有的已知的QR码都是25*25,如何通过ZXing把左图所有的信息点(黑色点)根据右图的坐标系转化为坐标(红色字母)
就是一个二维数组,你逐行扫图片就好了嘛。
<?php
$url = "http://sfault-image.b0.upaiyun.com/7c/6b/7c6bf5c40d66ac90be7fecf23d946046";
/*设置二维码图片大小*/
$w = $h = 130;
$p = $w/26;
/*切边操作去除不必要的白边*/
$oimg = imagecreatefrompng($url);
list($ow, $oh) = getimagesize($url);
$rmargin = 0;
for($x=0;$x<$ow;$x++) {
$rest = true;
for($y=0;$y<$oh;$y++) {
$c = array_values(imagecolorsforindex($oimg, imagecolorat($oimg, $x, $y)));
if($c[0]!=255&&$c[1]!=255&&$c[2]!=255) {
$rest = false;
break;
}
}
if($rest) $rmargin+=1;
else break;
}
$img = imagecreatetruecolor($w, $h);
imagecopyresampled($img, $oimg, 0, 0, $rmargin, $rmargin, $w, $h, $ow-$rmargin*2, $oh-$rmargin*2);
/*获取每个像素点的颜色*/
$blacks = array();
for($x=0;$x<$w;$x+=$p) {
for($y=0;$y<$h;$y+=$p) {
$c = array_values(imagecolorsforindex($img, imagecolorat($img, $x, $y)));
if($c[0]==0&&$c[1]==0&&$c[2]==0) $blacks[] = chr($x/$p+65).($y/$p);
}
}
print_r($blacks);
?>