2015-09-11 19 views
0

字節可以說我有一個ParseFile「MYIMAGE」轉換parsefile圖像中的Android

我如何轉換「MYIMAGE」從ParseFile到字節的Android編程[]類型?

我是在android上編程和parse.com的新手。任何幫助都感激不盡。

謝謝!

-edited-

我想轉換ParseFile MYIMAGE到字節,所以我可以將它傳遞給我的NewActivity.class

Bitmap bt = BitmapFactory.decodeResource(getResources(), myimage); 
ByteArrayOutputStream stream = new ByteArrayOutputStream(); 
bt.compress(Bitmap.CompressFormat.PNG, 100, stream); 
byte[] byteArray = stream.toByteArray(); 

Intent intent = new Intent(this, NewActivity.class); 
intent.putExtra("image", byteArray); 
startActivity(intent); 
+0

你可以添加一些代碼,顯示你迄今爲止做了什麼。 –

+0

嗨拉胡爾,謝謝你的回覆。我用一些代碼編輯了我的問題。 –

+0

你的代碼看起來不錯。請發佈logcat錯誤消息。我認爲你沒有正確得到parseFile。 – ved

回答

0

使用getDataInBackground() ParseFile的方法獲得直接字節[從] ParseImage。

ParseFile myImage; 
myImage.getDataInBackground(new GetDataCallback() { 

    @override 
    public void done(byte[] data, ParseException e) { 
    if (e == null) { 

     Intent intent = new Intent(this, NewActivity.class); 
     intent.putExtra("image", data); 
     startActivity(intent); 

    } else { 
     //byteArray not retrieved from parseImage handle the exception 

    } 
    } 
}); 
+0

謝謝ved!這對我有用。萬分感激! –

+0

它是我的榮幸。 – ved