我使用webview并访问图库图像文件。
我的问题是
1)我如何将此图像文件发送或上传到服务器或上传?
2)我应该发送哪一个
这是我的onActivityResult并从图库中获取了Bitmap文件。
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent){
if(requestCode==FILECHOOSER_RESULTCODE){
if(resultCode == RESULT_OK && null != intent){
Uri selectedImage = intent.getData();
web.loadUrl("javascript:setFileUri('" + selectedImage.toString() + "')");
String path = getRealPathFromURI(this, selectedImage);
web.loadUrl("javascript:setFilePath('" + path + "')");
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeFile(path,options);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream.toByteArray();
String imageBase64 = Base64.encodeToString(byteArray, Base64.DEFAULT);
String image = "data:image/png;base64," + imageBase64;
String temp = "./img/logo.png";
web.loadUrl("javascript:setImage('"+ image +"')");
//Iview01.setImageBitmap(bitmap);
//saveBitmaptoJpeg(bitmap,"img","temp",web,path);
}
}
}