3

I got code to upload picture and video to Face Book.. But i don't know how to convert image from gallery to image in bytes.. also data in bytes.. Any one can help me????

*Upload picture,
 Bundle params = new Bundle();
 params.putByteArray("picture", <image in bytes>);
 params.putString("message", "Have fun");
 mAsyncRunner.request("me/photos", params, "POST", new SampleUploadListener());* 

this is code for upload images...   
*Upload video,
Bundle params = new Bundle();
param.putString("filename", <dataName>);
param.putByteArray("video", <data in bytes>);
 mAsyncRunner.request("me/videos", param, "POST", new SampleUploadListener());**

this is code for upload images...    
Any one know how code for my question please post.....

thanks in advance

anoop
  • 782
  • 4
  • 12
  • 35

2 Answers2

1

Get file path from here

Try it -

FileInputStream is = new FileInputStream(new File(filePath));
ByteArrayOutputStream bs = new ByteArrayOutputStream();
int data;

while((data != is.read()) != -1)
   bs.write(data);

is.close();
byte[] raw = bs.toByteArray();
bs.close();
Community
  • 1
  • 1
Suvam Roy
  • 1,282
  • 2
  • 11
  • 21
  • 3
    FileInputStream is = new FileInputStream(new File(filePath)); ByteArrayOutputStream bs = new ByteArrayOutputStream(); int data; while((data != is.read()) != -1) bs.write(data); is.close(); byte[] raw = bs.toByteArray(); bs.close(); – anoop Apr 13 '12 at 11:40
  • data is not initalized do i have to initiate to 0 – Prasanna Anbazhagan Feb 01 '16 at 10:39
0

This is one way how you convert a bitmap to byte:

public static byte[] bitmapToByteArray(Bitmap bitmap){
    ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
    bitmap.compress(CompressFormat.PNG, 0, baos); 
    return baos.toByteArray();
}
Heinrisch
  • 5,835
  • 4
  • 33
  • 43