【问题标题】:How do I get an Android image and put it on the WebView?如何获取 Android 图像并将其放在 WebView 上?
【发布时间】:2019-08-14 07:03:15
【问题描述】:

我的网站当前配置了弹簧框架工作负载。我想要做的是取一个image 的Android 并将其浮动在Web 上。

导入Android images 将使用Android 图像选择模块完成。

这可能吗?

我必须将它保存为服务器上的image file。这可能吗?

存储当前图像文件的控制器

    @RequestMapping(value="/profile_image", method = RequestMethod.POST)
    public @ResponseBody Map<String, Object> profile_image(HttpServletRequest webRequest
            , @RequestParam(value="image", required=false) MultipartFile image

        Map<String, String> param = new HashMap<String, String>();
        Map<String, Object> result = new HashMap<String, Object>();
 try {

            // The image has been updated.
            String imagePath = "";
            if (image != null) {
                String Extension =  Config.USER_PROFILE_IMAGE_EXT;
                String fileName = "user_profile_"+ user_nickname + Utils.getCurrentTime("yyyyMMddHHmmssSSS");
                imagePath = Define.CONTENTS_FILE_PATH_4 + fileName + Extension ;

                File saveDir = new File(Define.CONTENTS_SAVE_PATH + Define.CONTENTS_FILE_PATH_4);
                if (!saveDir.isFile()) saveDir.mkdirs();

                image.transferTo(new File(Define.CONTENTS_SAVE_PATH + imagePath));

                String fileName_thumbnail = fileName + "_thumb" + Extension;
                File thumbnail = new File(Define.CONTENTS_SAVE_PATH + Define.CONTENTS_FILE_PATH_4 + fileName_thumbnail);

                thumbnail.getParentFile().mkdirs();
                Thumbnails.of(saveDir + "/" + fileName + Extension).size(Config.USER_PROFILE_IMAGE_WIDTH, Config.USER_PROFILE_IMAGE_HEIGHT).outputFormat("jpg").toFile(thumbnail);
            }

            param.put("imagepath", (!imagePath.equals("")) ? Define.PLATFORM_SERVER_HOST_NAME + imagePath : "");

            if (backOfficeDao.update_user_profile_image(param) < 1) {
                result.put("resultMsg", "Databases update fail..");

            } else {
                result.put("resultMsg", "Shop successful in modifying product information.");
            }


        } catch (Exception e) {
            e.printStackTrace();
            result.put("resultCode", Define.ERROR_CODE_001);
            result.put("resultMsg", "[ERROR] Server error");
        }

        return result;

    }

我应该从device store 中取出picture,将其放入WebView,将Image file 发送到WebService 并保存到服务器。

提前谢谢你

【问题讨论】:

  • 您需要从设备存储中拍摄照片并将其放在WebView上还是发送到WebService?不太清楚你在问什么,你能提供更多关于你需要什么的细节吗?谢谢
  • 嗨@axierjhtjz 是的,我应该从设备存储中获取图片,将其放在WebView 中,将文件发送到WebService 并保存到服务器。
  • 您的 webview 将只显示图像还是显示某种类型的 UI?如果只需要显示图片,可以加载一个base64到webview中。否则,您将需要使用 JavascriptInterface 来加载图像。
  • 方法是什么?

标签: javascript java android spring


【解决方案1】:

它通过与来自Android的多部分类型的服务器通信发送文件数据,它从我的控制器保存文件,读取我保存的数据并刷新它,允许用户查看他们拥有的图像文件数据进口的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-27
    相关资源
    最近更新 更多