php - 我的服务器图像变为 NULL

标签 php android mysql bitmap android-asynctask

我正在使用 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/

相关文章:

PHP '//' 的含义

java - 为什么 EditText 的值(非空)总是 true?

android - 在 Button 中动画化 Drawable 变化

php - 使用 PDF 格式的 FPDM 设置复选框和单选按钮

javascript - 使用 PhantomJs 登录后如何进入下一页?

java mysql 服务器变得越来越慢

PHP/MySQL - *-对多关系

mysql - SQL Server 与 MySQL : CONTAINS(* ,'FORMSOF(THESAURUS,word)' )

javascript - PHP 动态表,带有编辑/删除链接以打开弹出窗口

android - 保留 fragment 供以后显示的最佳实践