我正在使用 PHP 将图像上传到 MySQL 服务器,并且上传效果良好。
但是下载的时候就出现问题了。我已经测试了下载的链接,图像非常好,但在 ImageView 中显示它变成了一项繁琐的任务。 LogCat 窗口中未显示任何错误。位图变为 null(我使用 bitmap==null
进行比较)
我的 DoInBackground 和 OnPostExecute
@Override
protected Bitmap doInBackground(String... params) {
String id = params[0];
String add = "http://dakshansh.com/mybooks/image/getImage.php?id=" + imageId;
Log.d("Image","Link = "+add);
URL url = null;
Bitmap image = null;
try {
url = new URL(add);
image = BitmapFactory.decodeStream(url.openConnection().getInputStream());
} catch (IOException e) {
e.printStackTrace();
}
return image;
}
@Override
protected void onPostExecute(Bitmap b) {
super.onPostExecute(b);
//loading.dismiss();
if(b==null){
Log.d("Image","Image is null");
}
Log.d("Image","On onPostExecute()");
image.setImageBitmap(b);
Log.d("Image", "Image Set");
new ReadJSONFeedTask1().execute("http://dakshansh.com/mybooks/books/getmybooks.php?posterid="+id);
}
如果您需要的话,我会发布更多内容。 你可以看到图片here
最佳答案
使用 glide 将为您节省大量时间
ImageView imageView = (ImageView) findViewById(R.id.my_image_view);
Glide.with(this).load("your_url").into(imageView);
更多here
关于php - 我的服务器图像变为 NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41767773/