2015-04-22 114 views
0

如何將我的位圖圖像保存到parseObject? 這是我的代碼將位圖圖像保存到parseObject

Bundle extras = getIntent().getBundleExtra("extras"); 
    Bitmap thumbnail = (Bitmap) extras.get("data"); 

    ImageView img = (ImageView)findViewById(R.id.imageview1); 
    img.setImageBitmap(thumbnail) 

的代碼的parseObject

ParseObject movie = new ParseObject("movies"); 
       movies.put("title", title.getText().toString()); 
       movies.put("description", description.getText().toString()); 
       movies.saveInBackground(); 
       Toast.makeText(getApplicationContext(), "Done", 
Toast.LENGTH_SHORT).show() 

我如何保存位圖圖像到的parseObject 「電影」?

+1

發送是在Base64的形式。 –

+0

赤答案:http://stackoverflow.com/a/16476327 –

+0

好吧,我會檢查它,謝謝 –

回答

2

您可以使用ParseFile,以節省解析位圖

基本上你需要做這樣的事情

ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
     rotatedScaledMealImage.compress(Bitmap.CompressFormat.JPEG, 100, bos);// can use something 70 in case u want to compress the image 

     byte[] scaledData = bos.toByteArray(); 

     // Save the scaled image to Parse 
     photoFile = new ParseFile("image_to_be_saved.jpg", scaledData); 
     photoFile.saveInBackground(new SaveCallback() { 

      public void done(ParseException e) { 
       if (e != null) { 
        Toast.makeText(getActivity(), 
          "Error saving: " + e.getMessage(), 
          Toast.LENGTH_LONG).show(); 
       } else { 
        //filed saved successfully :) 
       } 
      } 
     }); 

,那麼你可以很容易地把ParseFile任何的parseObject 內這樣

ParseObject po = new ParseObject("anyObject"); 
po.put("file",parseFileObj); 

希望這會有幫助