如何在脱机模式下将图像存储在Parse本地数据存储中

时间:2015-03-21 12:51:38

标签: android parse-platform android-imageview local-datastore

我一直在寻找使用以下方式离线存储图像:

Bitmap image = ...
ByteArrayOutputStream stream = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] data = stream.toByteArray();
ParseFile file = new ParseFile("image.png", data);
file.saveInBackground();

photo = new Photo();
photo.setPhotoFile(file);
photo.pinInBackground(new SaveCallback() {
   @Override
   public void done(ParseException e) {
      if (e == null) {
        Log.d("SAVED", "SAVED SUCCESSFULLY");
      } else {
        Log.d("ERROR msg is :", e.getMessage());
      }
 });          

这会出错:

  

java.lang.IllegalStateException:无法对未保存的ParseFile进行编码。

但是当我使用" photo.saveInBackground"有用。我在Google上搜索过但无法找到合适的解决方案。

1 个答案:

答案 0 :(得分:0)

方法file.saveInBackground();是异步的。在file.save();保存后,您应该致电photo或实施回调以固定file

相关问题