3

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

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

提前致谢

4

2 回答 2

1

从这里获取文件路径

试试看 -

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();
于 2012-04-13T11:09:01.990 回答
0

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

public static byte[] bitmapToByteArray(Bitmap bitmap){
    ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
    bitmap.compress(CompressFormat.PNG, 0, baos); 
    return baos.toByteArray();
}
于 2012-04-13T11:05:28.667 回答