Image from gallery to image in bytes. Also data in bytes .. for downloading facebook in android

I have code to upload images and videos to Face Book .. But I don’t know how to convert image from gallery to image in bytes. Also data in bytes. Anyone 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.....

early

+3
source share
2 answers

Get the 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();
+1
source

This is one way to convert a bitmap to byte:

public static byte[] bitmapToByteArray(Bitmap bitmap){
    ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
    bitmap.compress(CompressFormat.PNG, 0, baos); 
    return baos.toByteArray();
}
0
source

All Articles