gpt4 book ai didi

android - 如何从 ParseObject 获取图像?

转载 作者:太空狗 更新时间:2023-10-29 16:34:54 29 4
gpt4 key购买 nike

我正在使用此代码从我的 ParseObject 中获取姓名和年龄字符串在解析中。我假设我也可以对图像文件做同样的事情。但是此代码不适用于图像。我可能做错了。或者也许我需要做一些完全不同的事情。有人可以帮我从 parseObject 获取图像文件吗?谢谢

public class MyAdapter extends ArrayAdapter<ParseObject> {

protected Context mContext;
protected List<ParseObject> MyPerson;

public MyAdapter (Context context, List<ParseObject> MyPerson){
super(context, R.layout.scustomlayout, MyPerson);
mContext = context;
mPerson = MyPerson;
}

@Override
public View getView (final int position, View convertView, ViewGroup Parent){
final ViewHolder holder;

if(convertView == null) {
convertView = LayoutInflater.from(mContext).inflate(R.layout.personcustomlayout, null);
holder = new ViewHolder();
holder.NameMain = (TextView) convertView.findViewById(R.id.NameHP);
holder.AgeMain = (TextView) convertView.findViewById(R.id.AgeHP);
holder.ImageMain = (ImageView) convertView.findViewById(R.id.ImageHP);

convertView.setTag(holder);


}else {
holder = (ViewHolder) convertView.getTag();
}

ParseObject personObject = mPerson.get(position);


//name
String name = personObject.getString("Name");
holder.NameMain.setText(name);

//Age
String age = personObject.getString("Age");
holder.AgeMain.setText(age);

ParseFile image = (ParseFile) personObject.get("Image");
image.getDataInBackground(new GetDataCallback() {
public void done(byte[] data, ParseException e) {
if (e == null) {
// Decode the Byte[] into bitmap
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
// Set the Bitmap into the imageView
holder.ImageMain.setImageBitmap(bmp);
} else {
Log.d("test", "There was a problem downloading the data.");
}
}
});

return convertView;
}

public static class ViewHolder {
ImageView ImageMain;
TextView NameMain;
TextView AgeMain;
}
}

最佳答案

ParseFile image = (ParseFile) personObject.get("Image");
image.getDataInBackground(new GetDataCallback() {
public void done(byte[] data, ParseException e) {
if (e == null) {
// Decode the Byte[] into bitmap
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0,data.length);
// Set the Bitmap into the imageView
holder.ImageMain.setImageBitmap(bmp);
} else {
Log.d("test", "There was a problem downloading the data.");
}
}
});

此外,将其添加到导入中:

import com.parse.ParseException;

关于android - 如何从 ParseObject 获取图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31235548/

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