我得到了这个代码,它从一个image
名为“dmlo”的地方drawable
上传到 php 服务器,我想要的不是从 drawable 中获取那张图片,而是从一个imageview
中获取它,我应该怎么做?我应该用另一个替换第一行中的任何代码吗?
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),R.drawable.dmlo);
ByteArrayOutputStream bao = new ByteArrayOutputStream();
bitmapOrg.compress(Bitmap.CompressFormat.JPEG, 90, bao);
byte [] ba = bao.toByteArray();
String ba1=Base64.encodeBytes(ba);
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("image",ba1));
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new
HttpPost("http://192.168.1.38/mobileappd/base.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
Toast.makeText(getBaseContext(), e.toString(),Toast.LENGTH_LONG).show();
}