gpt4 book ai didi

php - 从远程 mysql 数据库检索图像到 android

转载 作者:行者123 更新时间:2023-11-29 08:45:23 25 4
gpt4 key购买 nike

如何获取服务器上mysql中存储的图片?我想根据用户输入的值获取这些图像(意味着动态查询)。我想使用 json 将图像从 php 发送到 android。我使用静态查询在网络浏览器中成功显示了该图像,但是当我在 android 应用程序中看到 php 的响应时,它显示了一些 html 代码而不是图像。请帮助我解析图像 json 响应并显示该图像。以下是将图像发送到 android 的 php 代码。

 while($post = mysql_fetch_object($data))
{
$posts[] = $post;

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

echo '{"pprs":'.json_encode($posts).'}';

现在我收到回复:{"pprs":[{"pprs":null},{"pprs":null}]}

请帮助我。谢谢。

最佳答案

如果要使用 JSON,则需要将图像转换为字符串:

    $posts[] = base64_encode($post);

在 Android 端:

String base64image = jsonobject.getString("pprs");
byte[] rawImage = Base64.decode(base64image, Base64.DEFAULT);
Bitmap bmp = BitmapFactory.decodeByteArray(rawImage, 0, rawImage.length);
ImageView imageview = (ImageView) findViewById(R.id.imgPicture);
imageview.setImageBitmap(bmp);

关于php - 从远程 mysql 数据库检索图像到 android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12647224/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com