从图库到图像的图像以字节为单位..还有以字节为单位的数据..用于在android中上传的facebook

时间:2012-04-13 10:56:55

标签: android

我有代码将图片和视频上传到Face Book .. 但我不知道如何将图像从图库转换为图像的字节数。还有数据以字节为单位..任何人都可以帮助我????

*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.....

提前致谢

2 个答案:

答案 0 :(得分:1)

Get file path from here

试一试 -

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 :(得分:0)

这是将位图转换为字节的一种方法:

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