gpt4 book ai didi

java - 获取 Parsefile 到 ImageView

转载 作者:行者123 更新时间:2023-11-30 11:25:38 25 4
gpt4 key购买 nike

我想从解析到 ImageView 获取文件。我试图通过“getDataInBackgound”获得,但是当我调用此方法时,UI 卡住了,我得到了最后一张图片。

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);

}
});

最佳答案

我认为您必须使用 Picasso 加载图像或 ImageLoader 类。我有同样的疑问,我也使用了 ParseImageView。这是我的代码:

使用异步任务从 parse.com 检索 ParseFile(图像):

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;
}
}

在你的布局中像使用 ImageView 一样使用它:

<com.parse.ParseImageView
android:id="@id/imgv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true />

使用这一行在 ParseImageView 中加载图片:

Picasso.with(this).load(parsefile.getUrl()).into(parseimageview);

另一种快速加载更大图片的方法是使用 ImageLoader。请查看this .

希望这有帮助:)

关于java - 获取 Parsefile 到 ImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20215151/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com