public class Profile extends Activity {
ImageView personal_ImageView;
private static final int SELECT_PICTURE = 100;
private String selectedImagePath;
private ParseObject totem;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
personal_ImageView = (ParseImageView) findViewById(R.id.personal_imageView);
ParseUser currentUser = ParseUser.getCurrentUser();
String currentUserUsername = currentUser.getUsername();
Bitmap bitmap = ((BitmapDrawable) personal_ImageView.getDrawable()).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] data = stream.toByteArray();
ParseFile file = new ParseFile(selectedImagePath, data);
file.saveInBackground();
final ParseObject gameScore = new ParseObject("imageProfile");
gameScore.put("image", file);
gameScore.put("user", currentUserUsername);
gameScore.saveInBackground();
personal_ImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE);
ParseFile file = gameScore.getParseFile("image");
final ParseImageView imageView = (ParseImageView) findViewById(R.id.personal_imageView);
imageView.setParseFile(file);
imageView.loadInBackground(new GetDataCallback() {
public void done(byte[] data, ParseException e) {
if (e == null){
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
if (bitmap != null) {
personal_ImageView.setImageBitmap(bitmap);
}
}
// The image is loaded and displayed!
int oldHeight = imageView.getHeight();
int oldWidth = imageView.getWidth();
Log.v("LOG!!!!!!", "imageView height = " + oldHeight); // DISPLAYS 90 px
Log.v("LOG!!!!!!", "imageView width = " + oldWidth); // DISPLAYS 90 px
}
});
}
});
}
Please help me guys... I can upload the image to parse but i am not be able to retrieve the image and put it into the parse imageview! What am i doing wrong in the code?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…