Bitmap轉String
ByteArrayOutputStream bitaos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG,100,bitaos);
byte[] bytes=bitaos.toByteArray();
String BitmapString = Base64.encodeToString(bytes,Base64.DEFAULT);
By File 絕對路徑
FileInputStream fileInputStream = new FileInputStream("你的圖片絕對路徑");
ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream();
//uploadBuffer(要傳到webservice介面上)
byte[] buffer = new byte[1024];
int count = 0;
while((count=fileInputStream.read(buffer))>=0){
byteArrayOutputStream.write(buffer,0,count);
}
Stirng FileString=Base64.encodeToString(byteArrayOutputStream.toByteArray(),Base64.DEFAULT);
留言列表