从Parse / Android获取图像

时间:2015-05-09 18:12:44

标签: android parse-platform

我正在尝试加载存储在Parse中的图像;使用本教程中的代码:https://parse.com/tutorials/mealspotting我编写了这段代码:

 mProfileImage = mCurrentUser.getParseFile("ProfilePhoto");


        mProfilePhoto = (ParseImageView) findViewById(R.id.meal_preview_image);




        mProfilePhoto.setParseFile(mProfileImage);
        mProfilePhoto.loadInBackground(new GetDataCallback() {
            @Override
            public void done(byte[] data, ParseException e) {
                mProfilePhoto.setVisibility(View.VISIBLE);
            }
        });

我的布局中有这个:

<com.parse.ParseImageView
        android:id="@+id/meal_preview_image"
        android:layout_width="wrap_content"
        android:layout_height="200dp" />

我正在使用这个protected ParseImageView mProfilePhoto;,一个ParseImageView。当我运行应用程序时,图像不会出现。

1 个答案:

答案 0 :(得分:2)

这就是我通常得到ImageUrl并在ImageView中显示它的方式,其中包括图像缓存机制。你需要parseObject。

String Imgurl;
ParseFile image = (ParseFile) parseObject.get("ProfilePhoto"); 
if (image!=null) {
   Log.d("track", image.getUrl());
   Imgurl = image.getUrl();
} 

然后使用像Universal Image Loader这样的图像缓存库来​​避免OutOfMemory异常和平滑滚动。

imageLoader.displayImage(Imgurl, imageView);