Reputation: 71
I want to get file from parse to ImageView. I'm try to get by "getDataInBackgound" But when I call to this method' UI is stuck and I get the last image.
ParseFile image = tableParseObjects.getParseFile(PARSE_IMAGES);
image.getDataInBackground(new GetDataCallback() {
@Override
public void done(byte[] data, ParseException e) {
Bitmap bitpic = BitmapFactory.decodeByteArray(data, 0, data.length);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitpic.compress(Bitmap.CompressFormat.PNG, 100, stream);
vectorSample.setPic(bitpic);
}
});
Upvotes: 2
Views: 1389
Reputation: 301
I think you have to load the image using Picasso or the ImageLoader class. I had the same doubt and I used a ParseImageView too. This is my code:
Retrieve from parse.com the ParseFile (the image) with an asynctask:
public class BackgroundQuery extends AsyncTask<Object, Void, Object> {
private String id;
public BackgroundQuery(String id) {
this.id = id;
}
@Override
protected Object doInBackground(Object... params) {
Object o = null;
try {
ParseQuery<ParseObject> query = ParseQuery.getQuery(params[0]
.getClass().getSimpleName());
query.whereEqualTo("objectId", id);
List<ParseObject> result = query.find();
if (result != null) {
for (ParseObject obj : result) {
o = obj.getParseFile("photo"); // Photo is the ParseFile
}
}
} catch (ParseException e) {
Log.e(TAG, e.getMessage());
}
return o;
}
}
In your layout use this like an ImageView:
<com.parse.ParseImageView
android:id="@id/imgv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true />
Use this line for load the picture in the ParseImageView:
Picasso.with(this).load(parsefile.getUrl()).into(parseimageview);
An alternative to load bigger pics quickly it´s using an ImageLoader. Please check this.
Hope this help :)
Upvotes: 1