保存从Parse.com下载的图像

时间:2015-10-27 10:02:20

标签: java android image

在我的应用程序中,我有很多图像,其中5个可以更改。我使用Parse.com上传我的新图片。 这段代码效果很好,但是我无法将新图像保存到我的应用程序中。我怎么能这么容易做到?

            public class PrasePhotoProba extends Activity {
static final String TAG = "myLogs";
Button button;
private ProgressDialog progressDialog;

/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Get the view from main.xml
    setContentView(R.layout.photo);
    // Show progress dialog

    // Locate the button in main.xml
    button = (Button) findViewById(R.id.button);

    // Capture button clicks
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {

            progressDialog = ProgressDialog.show(PrasePhotoProba.this, "",
                    "Downloading Image...", true);

            // Locate the class table named "ImageUpload" in Parse.com
            ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
                    "newImage");

            // Locate the objectId from the class
            query.getInBackground("1",
                    new GetCallback<ParseObject>() {

                        public void done(ParseObject object,
                                         ParseException e) {

                            ParseFile fileObject = (ParseFile) object
                                    .get("image");
                            fileObject
                                    .getDataInBackground(new GetDataCallback() {

                                        public void done(byte[] data,
                                                         ParseException e) {
                                            if (e == null) {
                                                Log.d("test",
                                                        "We've got data in data.");
                                                // Decode the Byte[] into
                                                // Bitmap
                                                Bitmap bmp = BitmapFactory
                                                        .decodeByteArray(
                                                                data, 0,
                                                                data.length);

                                                // Get the ImageView from
                                                // main.xml
                                                ImageView image = (ImageView) findViewById(R.id.image);

                                                // Set the Bitmap into the
                                                // ImageView
                                                image.setImageBitmap(bmp);


                                                // Close progress dialog
                                                progressDialog.dismiss();



                                            } else {
                                                Log.d("test",
                                                        "There was a problem downloading the data.");
                                            }

                                        }

                                    });
                        }
                    });



        }


    });





}

1 个答案:

答案 0 :(得分:0)

使用以下代码保存位图:

文件文件=新文件(Environment.getExternalStorageDirectory()+ filepath,GiveAnyimageName +&#34; .png&#34;);     FileOutputStream fOut = new FileOutputStream(file);

bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
fOut.flush();
fOut.close();