gpt4 book ai didi

php - 将多个图像从 MySQL 数据库拉取到 Android 设备的最有效方法

转载 作者:行者123 更新时间:2023-11-29 14:47:00 24 4
gpt4 key购买 nike

简而言之,我的应用程序需要从 MySQL 数据库中提取图像。由于提取的图像将取决于用户位置,我不能只对图像文件路径进行硬编码。

到目前为止,我已经尝试仅使用 PHP 脚本,该脚本应该允许应用程序将图像从表中提取到我的数据库中,但我还没有取得任何成功的结果。

在我的应用程序中,我使用以下方法将流拉取并解码为手机/应用程序可以使用的位图:

public static void createIcons(Resources res) throws IOException {
String url1 = " http://mysite.iscool/file-get.php ";
URL ulrn = new URL(url1);
HttpURLConnection con = (HttpURLConnection)ulrn.openConnection();
InputStream is = con.getInputStream();
//end of lines added

markIcon=BitmapFactory.decodeStream(is);

由于到目前为止我似乎无法使用此方法从数据库将图像返回到设备,所以我想知道我应该进入什么样的方向。我在这里看到了很多不同的方法解释,但我'我不太确定我尝试使用的方法是否能够达到我需要的目的。

此外,我还看到提到 REST 服务和其他从 mysql 数据库表中提取图像的方法。那么有人有从 MySQL 数据库中提取多个图像的建议/教程/示例吗?

顺便说一下,这是我用来尝试将图像返回到设备的代码:

<?php
//----------------------------------------------------------
//
//---------------------------------------------------------
// access server
//---------------------------------------------------------
include("fLADB.php");
//
$dbQuery = "SELECT File FROM mark_image_store where imageid =(SELECT MAX(imageid) from
mark_image_store);";

//-----------------------------------------------------------
// selecting into a single element variable
// stores only the first field which is the file data
//-----------------------------------------------------------
$result = mysql_query($dbQuery) or die(mysql_error());
//-----------------------------------------------------------
//reserved for when there is file ext data available.
//to format http headers
//Do not need for use by the phone.
//header("Content-type: image/jpeg");
//if ($ext = "png")
//-------------------------------------------------------------
// use imagejpeg, imagepng?
//-------------------------------------------------------------
header("Content-type: image/png");
print mysql_result($result, 0);
mysql_close();
?>

因此,在查看我的 PHP 和 Android 代码之后,有人可以给我一些关于我下一步应该朝哪个方向发展的建议吗?我是否应该重新编写 Android 端代码并使用 REST 服务或 Web 服务,或者 PHP 脚本服务器端足以处理图像返回。

任何建议/教程/或示例将不胜感激,谢谢。

最佳答案

您可以通过单个查询轻松提取多个图像。但是您一次只能传输一张图像,除非您使用某种封装(例如 .zip)。

如果您通过 HTTP 提供图像,那么您肯定一次只能提供一张图片。有一些技巧可以让您提供一个图像,其中平铺一系列较小的图像,并将它们显示在限制大小的 div 中作为图 block / Sprite ,但这需要客户端干预。

关于php - 将多个图像从 MySQL 数据库拉取到 Android 设备的最有效方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6754598/

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