这是我的数据库中的imagepath
附带的API。
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格式保存来自我的SharedPreferences数据库的这些图像。
用这个:
public String getImageUrl() {
return PreferenceManager.getDefaultSharedPreferences(context)
.getString("url");
}
public saveImageUrl(String url) {
return PreferenceManager.getDefaultSharedPreferences(context).edit()
.putString("url", "").commit();
}
如果你想保存一个图像列表,还有其他一些options供你使用
您可以将该图像转换为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加载一次,然后从缓存加载它们。对于缓存您可以阅读Caching bitmaps或者您可以使用Image加载库,它提供了一种非常有效的缓存方式,并使图像加载/缓存面包和黄油。下面是您可以使用的一些参考。