简体   繁体   English

保存从Parse.com下载的图像

[英]Save image downloaded from Parse.com

In my application i have got a lot of images, 5 of them can change. 在我的应用程序中,我有很多图像,其中5张可以更改。 I use Parse.com to upload my new image. 我使用Parse.com上传新图像。 This code works great, but i cant save NEW image to my application. 这段代码很好用,但是我无法将新图像保存到我的应用程序中。 How i can do this easily? 我如何轻松做到这一点?

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

                                        }

                                    });
                        }
                    });



        }


    });





}

Save Bitmap using this code: 使用以下代码保存位图:

File file = new File(Environment.getExternalStorageDirectory() + filepath, GiveAnyimageName + ".png"); 文件=新文件(Environment.getExternalStorageDirectory()+文件路径,GiveAnyimageName +“ .png”); FileOutputStream fOut = new FileOutputStream(file); FileOutputStream fOut =新的FileOutputStream(file);

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM