我想从解析中检索图像!在解析中存储图像有效!如何从imageview中解析图像?

时间:2015-08-29 14:07:31

标签: android parse-platform

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

请帮助我们......我可以上传图片进行解析,但我无法检索图像并将其放入解析图像视图中!我在代码中做错了什么?

1 个答案:

答案 0 :(得分:0)

你可能想看看这个:

http://square.github.io/picasso/

干杯!

代码我用来使用文件URL从解析中检索图像。

 ParseFile file = message.getParseFile(Insert Key File Here);
 Uri fileUri = Uri.parse(file.getUrl());
 Picasso.with(this).load(imageUri.toString()).into(imageView);

如果您愿意,可以向Picasso添加回调:

Picasso.with(this).load(imageUri.toString()).into(imageView, new    com.squareup.picasso.Callback() {
        @Override
        public void onSuccess() {

            //Success
        }

        @Override
        public void onError() {

         //Error Occurred  

        }
    });