0

「dmlo」image呼ばれるものを取得してphpサーバーにアップロードするこのコードを取得しました。ドローアブルからその写真を取得する代わりに、から取得したいのですが、どうすればよいですか? 最初の行のコードを別のコードに置き換える必要がありますか?drawableimageview

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();
}
4

2 に答える 2

1

このコードを確認してください - ドローアブルが割り当てられていない場合は null を返す可能性があります

imageView.getDrawable();
于 2013-01-08T12:43:39.600 に答える
0

これを試してみてください。画像を描画可能な形式で返し、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();

それはあなたの問題を解決します。

于 2013-01-08T12:42:40.183 に答える