保存来自HTML格式数据库的共享流程中的图像列表



这是我的API,来自数据库中的imagepath

APIInterface api = APiClient.getApiService();
            Call<AdMain> call = api.getAd(lid);
            call.enqueue(new Callback<AdMain>() {
                @Override
                public void onResponse(Call<AdMain> call, Response<AdMain> response) {
                    if (response.isSuccessful()) {
                        if (response.body().getData().size() == 0) {
                            LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 3.78f);
                            expandid.setLayoutParams(param);
                        } else if (response.body().getData().size() == 1) {
                            Picasso.with(ShowNotesActivity.this).load("http://124.41.193.135:88/" + response.body().getData().get(0).getImagePath()).into(imgad);
                        } else {
                            imagepath = new ArrayList<>();
                            imageadlist = new ArrayList<>();
                            for (int i = 0; i < response.body().getData().size(); i++) {
                                imageadlist.add(response.body().getData().get(i).getImagePath());
                                endIndex = i;
                            }
                            Log.d("size", "onResponse: "+imagepath.size());
                            nextimage();
                        }
                    }
                }
                @Override
                public void onFailure(Call<AdMain> call, Throwable t) {
                }
            });

现在,我想以HTML格式保存来自我共享的数据库的这些图像。

使用以下:

   public String getImageUrl() {
        return PreferenceManager.getDefaultSharedPreferences(context)
                .getString("url");
    }
    public saveImageUrl(String url) {
        return PreferenceManager.getDefaultSharedPreferences(context).edit()
                .putString("url", "").commit();
    }

如果要保存图像列表,还有其他一些选择

您可以将该图像转换为base64,并可以将其保存在共享的偏好

public static String encodeToString(BufferedImage image, String type) {
    String imageString = null;
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {
        ImageIO.write(image, type, bos);
        byte[] imageBytes = bos.toByteArray();
        BASE64Encoder encoder = new BASE64Encoder();
        imageString = encoder.encode(imageBytes);
        bos.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return imageString;
}

您在说什么caching。您可以在存储中加速映像,该存储中从Internet加载一次并下次加载它们。用于缓存您可以读取缓存位图,也可以使用图像加载库,该库为缓存提供了非常有效的方法,并使图像加载/缓存面包和黄油。您可以使用一些参考。

link1

link2

link3

最新更新