我从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();
}
答案 0 :(得分:1)
检查此代码 - 如果未指定drawable,则可能返回null
imageView.getDrawable();
答案 1 :(得分:0)
试试这个,它以drawable格式返回图像,从imageview获取图像后,你可以将Drawable的对象传递给php服务器。
ImageView mImg1 = (ImageView) findViewById(R.id.mImg1);
// For get Drawable from Image
Drawable d = mImg1.getDrawable();
// For Convert Drawable to Bitmap
Bitmap bitmapOrg = ((BitmapDrawable)d).getBitmap();
它将解决您的问题。