0

几天前我发布了将 MySQL 中 blob 传递到 IOS NSData\UIImage 中,但还没有找到解决方案。我的具体问题是,当我从数据库、blob 或文本中检索图像时,它返回 NULL,其中没有变量的行只返回空白

while ($row = mysql_fetch_array($result)) {

 $add = array(); 
 $add["Id"] = $row["Id"]; 
 $add["Mail"] = $row["Mail"];
 $add["Category"] = $row["Category"]; 
 $add["Phone"] = $row["Phone"]; 
 $add["Msgs"] = $row["Msgs"];
 //image from blob
 $add["Picture"] = $row["Picture"];

 // push single add into final response array 
 array_push($response["adds"], $add); 
}

有没有其他方法可以处理来自 blob\text 的图像?!我尝试了https://stackoverflow.com/a/6273415/1333294但对我没有任何作用。

4

2 回答 2

1

最后!!

    $img = $row["Picture"];
    $b64img = base64_encode ($img);
    $b64img = mysql_real_escape_string($b64img);
    $add["Picture"] = $b64img;

就那么简单!并且 xcode 将其作为 base64 字符串和 nut NULL 获取。感谢您的建议...

于 2013-04-16T19:50:29.717 回答
0

添加以下代码

header("Content-type: image/jpeg");

echo $row['picture'];

// Display image with img html tag

echo '<img src="data:image/jpeg;base64,' . base64_encode( $row['picture'] ) . '" />';

echo 'Hello world.';

请找到示例代码

$response["adds"] = array();
$add = array(); 
$add["Id"] = 1; 
$add["Mail"] = "test@mm.com";
$add["Category"] = "category"; 
$add["Phone"] = "1234567"; 
$add["Msgs"] = "ths s txt msg";
//image from blob
$add["Picture"] = "pciture";

// push single add into final response array 
array_push($response["adds"], $add); 
print_r($response["adds"]);
header("Content-type: image/jpeg");
print $response["adds"][0]['Picture'];
于 2013-04-16T11:56:39.533 回答