gpt4 book ai didi

java - 在 Parse 上检索文件 - 图像

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

我已经成功地将图像文件存储到解析中。我的问题在于检索它。从某种意义上说,在注册过程中,用户被要求上传个人资料图片,并且该图像随后被存储为解析图像。我的问题在于检索它,除了提取潜在匹配项的姓名、标题、年龄等信息外,我还希望能够检索图片。

下面是代码,我在其中检索字符串信息,但我也想在其中检索文件。

public class MatchingActivity extends Activity {

private String currentUserId;
private ArrayAdapter<String> namesArrayAdapter;
private ArrayList<String> names;
private ListView usersListView;
private Button logoutButton;
String userGender = ParseUser.getCurrentUser().getString("Gender");
String activityName = ParseUser.getCurrentUser().getString("ActivityName");
Number maxDistance = ParseUser.getCurrentUser().getNumber("Maximum_Distance");


String userLookingGender = ParseUser.getCurrentUser().getString("Looking_Gender");
Number minimumAge = ParseUser.getCurrentUser().getNumber("Minimum_Age");
Number maximumAge = ParseUser.getCurrentUser().getNumber("Maximum_Age");
Number userage = ParseUser.getCurrentUser().getNumber("Age");



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.matching);

logoutButton = (Button) findViewById(R.id.logoutButton);
logoutButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ParseUser.logOut();
Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
startActivity(intent);
}
});

setConversationsList();
}
private void setConversationsList() {
currentUserId = ParseUser.getCurrentUser().getObjectId();
names = new ArrayList<String>();
// String userActivitySelectionName = null;

ParseQuery<ParseUser> query = ParseUser.getQuery();

// query.whereEqualTo("ActivityName",userActivitySelectionName);

query.whereNotEqualTo("objectId", ParseUser.getCurrentUser().getObjectId());
// users with Gender = currentUser.Looking_Gender
query.whereEqualTo("Gender", userLookingGender);
// users with Looking_Gender = currentUser.Gender
query.whereEqualTo("Looking_Gender", userGender);
query.setLimit(1);
query.whereEqualTo("ActivityName", activityName);
query.whereGreaterThanOrEqualTo("Minimum_Age", minimumAge).whereGreaterThanOrEqualTo("Age", userage);
query.whereLessThanOrEqualTo("Maximum_Age", maximumAge).whereLessThanOrEqualTo("Age", userage);
// query.whereWithinKilometers("Maximum_Distance", point, maxDistance)





query.findInBackground(new FindCallback<ParseUser>() {

public void done(List<ParseUser> userList, ParseException e) {
if (e == null) {
for (int i=0; i<userList.size(); i++) {
names.add(userList.get(i).get("Name").toString());
names.add(userList.get(i).get("Headline").toString());
names.add(userList.get(i).get("Age").toString());

// names.add(userList.get(i).getParseObject("ProfilePicture").;


}




usersListView = (ListView)findViewById(R.id.usersListView);
namesArrayAdapter =
new ArrayAdapter<String>(getApplicationContext(),
R.layout.user_list_item, names);
usersListView.setAdapter(namesArrayAdapter);

usersListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> a, View v, int i, long l) {
openConversation(names, i);
}
});

} else {
Toast.makeText(getApplicationContext(),
"Error loading user list",
Toast.LENGTH_LONG).show();
}
}
});
}

public void openConversation(ArrayList<String> names, int pos) {
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("Name", names.get(pos));
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> user, ParseException e) {
if (e == null) {
Intent intent = new Intent(getApplicationContext(), MessagingActivity.class);
intent.putExtra("RECIPIENT_ID", user.get(0).getObjectId());
startActivity(intent);
} else {
Toast.makeText(getApplicationContext(),
"Error finding that user",
Toast.LENGTH_SHORT).show();
}
}
});
}
}

如果您有任何问题,如果喜欢的话。

更新图片代码

ParseFile image = (ParseFile) userData.getParseFile("ProfilePicture");

//call the function

displayImage(image, image_expert);
//and here is the function

private void displayImage(ParseFile thumbnail, final ImageView img) {

if (thumbnail != null) {
thumbnail.getDataInBackground(new GetDataCallback() {

@Override
public void done(byte[] data, ParseException e) {

if (e == null) {
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0,
data.length);

if (bmp != null) {

Log.e("parse file ok", " null");
img.setImageBitmap(Bitmap.createScaledBitmap(bmp,
(display.getWidth() / 5),
(display.getWidth() /50), false));
img.setImageBitmap(getRoundedCornerBitmap(bmp, 10));
img.setPadding(10, 10, 0, 0);



}
} else {
Log.e("paser after downloade", " null");
}

}
});
} else {

Log.e("parse file", " null");

// img.setImageResource(R.drawable.ic_launcher);

img.setPadding(10, 10, 10, 10);
}

}
names.add(userList.get(i).get("Age").toString());
names.add(userList.get(i).get("ActivityName").toString());


// names.add(userList.get(i).getParseObject("ProfilePicture").;


}

Activity 代码

public class Fragment1 extends Fragment {

private String currentUserId;
private ArrayAdapter<String> namesArrayAdapter;
private ArrayList<String> names;
private ListView usersListView;
private Button logoutButton;
String userGender = ParseUser.getCurrentUser().getString("Gender");
String activityName = ParseUser.getCurrentUser().getString("ActivityName");
Number maxDistance = ParseUser.getCurrentUser().getNumber("Maximum_Distance");
String userLookingGender = ParseUser.getCurrentUser().getString("Looking_Gender");
Number minimumAge = ParseUser.getCurrentUser().getNumber("Minimum_Age");
Number maximumAge = ParseUser.getCurrentUser().getNumber("Maximum_Age");
Number userage = ParseUser.getCurrentUser().getNumber("Age");

@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

setConversationsList();

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment1_layout, container, false);


return view;
}

private void setConversationsList() {
currentUserId = ParseUser.getCurrentUser().getObjectId();
names = new ArrayList<String>();
// String userActivitySelectionName = null;

ParseQuery<ParseUser> query = ParseUser.getQuery();

// query.whereEqualTo("ActivityName",userActivitySelectionName);

query.whereNotEqualTo("objectId", ParseUser.getCurrentUser().getObjectId());
// users with Gender = currentUser.Looking_Gender
query.whereEqualTo("Gender", userLookingGender);
// users with Looking_Gender = currentUser.Gender
query.whereEqualTo("Looking_Gender", userGender);
query.setLimit(1);
query.whereEqualTo("ActivityName", activityName);
//query.whereGreaterThanOrEqualTo("Age", minimumAge);
//query.whereLessThanOrEqualTo("Age", maximumAge);
query.orderByDescending("Name");




query.findInBackground(new FindCallback<ParseUser>() {

public void done(List<ParseUser> userList, ParseException e) {
if (e == null) {
for (int i=0; i<userList.size(); i++) {
names.add(userList.get(i).get("Name").toString());
names.add(userList.get(i).get("Headline").toString());

ParseFile image = (ParseFile) userData.getParseFile("ProfilePicture");

//call the function

displayImage(image, image_expert);
//and here is the function

private void displayImage(ParseFile thumbnail, final ImageView img) {

if (thumbnail != null) {
thumbnail.getDataInBackground(new GetDataCallback() {

@Override
public void done(byte[] data, ParseException e) {

if (e == null) {
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0,
data.length);

if (bmp != null) {

Log.e("parse file ok", " null");
img.setImageBitmap(Bitmap.createScaledBitmap(bmp,
(display.getWidth() / 5),
(display.getWidth() /50), false));
img.setImageBitmap(getRoundedCornerBitmap(bmp, 10));
img.setPadding(10, 10, 0, 0);



}
} else {
Log.e("paser after downloade", " null");
}

}
});
} else {

Log.e("parse file", " null");

// img.setImageResource(R.drawable.ic_launcher);

img.setPadding(10, 10, 10, 10);
}

}
names.add(userList.get(i).get("Age").toString());
names.add(userList.get(i).get("ActivityName").toString());


// names.add(userList.get(i).getParseObject("ProfilePicture").;


}




usersListView = (ListView)getActivity().findViewById(R.id.userlistview);
namesArrayAdapter =
new ArrayAdapter<String>(getActivity().getApplicationContext(),
R.layout.user_list_item, names);
usersListView.setAdapter(namesArrayAdapter);

usersListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> a, View v, int i, long l) {
openConversation(names, i);
}
});

} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list",
Toast.LENGTH_LONG).show();
}
}
});
}

public void openConversation(ArrayList<String> names, int pos) {
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("Name", names.get(pos));
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> user, ParseException e) {
if (e == null) {
Intent intent = new Intent(getActivity().getApplicationContext(), MessagingActivity.class);
intent.putExtra("RECIPIENT_ID", user.get(0).getObjectId());
startActivity(intent);
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error finding that user",
Toast.LENGTH_SHORT).show();
}
}
});
}
}

以下行的问题

                private void displayImage(ParseFile thumbnail, final ImageView img) {
Multiple markers at this line
- Syntax error on token ",", ;
expected
- Syntax error on token "(", ;
expected
- Syntax error on token ")", ;
expected

最佳答案

看看下面的内容是否有帮助:

ParseUser currentUser = ParseUser.getCurrentUser();
currentUser.fetchInBackground(new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
ParseFile file = (ParseFile)object.get("image");
if(file != null){
file.getDataInBackground(new GetDataCallback() {
public void done(byte[] data, ParseException e) {
if (e == null) {
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
if(bitmap != null){
imageAccount.setImageBitmap(bitmap);
}else{
Log.d(TAG, "file null?");
}
} else {
Log.d(TAG, "ParseFile ParseException: " + e.toString());
}
}
});
}else{
Log.d(TAG, "ParseFile is null");
}
} else {
Log.d(TAG, "ParseException: " + e.toString());
}
}
});

关于java - 在 Parse 上检索文件 - 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25334395/

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