2012-04-13 4 views
3

Ich habe Code zum hochladen Bild und Video zu Gesicht Buch .. Aber ich weiß nicht, wie man Bild von Galerie zu konvertieren Bild in Bytes .. auch Daten in Bytes .. Jeder kann mir helfen ????Bild von der Galerie zu Bild in Bytes .. auch Daten in Bytes .. für Facebook hochladen in Android

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

Dank im Voraus

Antwort

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(); 
+3

Fileinputstream ist = ne w FileInputStream (neue Datei (Dateipfad)); ByteArrayOutputStream bs = neues ByteArrayOutputStream(); int Daten; while ((Daten! = Is.read())! = -1) bs.write (data); is.close(); byte [] rohe = bs.toByteArray(); bs.close(); – anoop

+0

Daten sind nicht initialisiert, muss ich auf 0 initiieren –

0

Dies ist eine Möglichkeit, wie Sie ein Bitmap in Byte konvertieren:

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