我的 MainActivity 中有此代码,它必须从 Parse 云查看图像和图像的名称。我想查看我的 Parse 数据库中的图像及其文件名。
postsQueryAdapter = new ParseQueryAdapter<ParseConfig>(this, factory) {
@Override
public View getItemView(ParseConfig post, View view, ViewGroup parent) {
if (view == null) {
view = View.inflate(getContext(), R.layout.filter_view, null);
}
ImageView contentView = (ImageView) view.findViewById(R.id.content_view);
TextView usernameView = (TextView) view.findViewById(R.id.username_view);
contentView.setText();post.getImage().getFile());
usernameView.setText(post.getUser().getUsername());
return view;
}
};
这是我的filter_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/content_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/username_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
和 ParseConfig.java
public class ParseConfig extends ParseObject {
public void setFile(Bitmap value) {
put("FilterFile",value);
}
public ParseUser getUser() {
return getParseUser("user");
}
public ParseFile getImage() {
return getParseFile("FilterFile");
}
public ParseGeoPoint getLocation() {
return getParseGeoPoint("PlaceLocation");
}
public static ParseQuery<ParseConfig> getQuery() {
return ParseQuery.getQuery(ParseConfig.class);
}
}
最佳答案
我可能弄错了,但您可能必须将图像转换为 ParseFile,然后转换为位图,然后将其另存为 ImageView 。 尝试一下
ParseFile img = (ParseFile) post.getImage("YourImageNameOnDatabase").getFile());
img.getDataInBackground(new GetDataCallback() {
@Override
public void done(byte[] data, ParseException e) {
Bitmap bit = BitmapFactory.decodeByteArray(data, 0, data.length);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bit.compress(Bitmap.CompressFormat.PNG, 100, stream);
contentView.setImageBitmap(bit);
}
});
关于java - 尝试在 Android 上从解析和查看中调用图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34482120/