0
public void onClick(View v) {
    // TODO Auto-generated method stub

    switch (v.getId()) {

    case R.id.image1:
        i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(i, cameraData);

        break;
    case R.id.image2:
        ii = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(ii, cameraData);
    }
}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == RESULT_OK) {
        Bundle extras = data.getExtras();
        bmp = (Bitmap) extras.get("data");
        view1.setImageBitmap(bmp);
        view2.setImageBitmap(bmp);
    }
}

我想用相机拍摄两张图像并将这些图像显示为两个单独ImageViews的图像。我拍了一张照片,但它在两个图像中都显示了相同的图像ImageViews。请帮助我真的被卡住了。

4

3 回答 3

2

您可以尝试以下方法:

public void onClick(View v) { // TODO Auto-generated method stub

    switch (v.getId()) {

    case R.id.image1:
        i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(i, 1);

        break;
    case R.id.image2:
        ii = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(ii, 2);
  }
}

进而,

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    switch(requestCode){
    case 1:
       if(resultCode == RESULT_OK){
          Bundle extras = data.getExtras();
          bmp = (Bitmap) extras.get("data");
          view1.setImageBitmap(bmp);
       }
       break;
    case 2:
       if(resultCode == RESULT_OK) {
            Bundle extras = data.getExtras();
            bmp = (Bitmap) extras.get("data");
            view2.setImageBitmap(bmp);
        }
       break;
     }
}
于 2013-03-18T09:02:48.383 回答
1

试试这个:

public void onClick(View v) {
        // TODO Auto-generated method stub

        switch (v.getId()) {
i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        case R.id.image1:

            startActivityForResult(i, 101);

            break;
        case R.id.image2:

            startActivityForResult(i, 102);
      }
}


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);

        if (if (requestCode == 101 && resultCode == RESULT_OK)) {
            Bundle extras = data.getExtras();
            bmp = (Bitmap) extras.get("data");
            view1.setImageBitmap(bmp);

}
        if (if (requestCode ==102 && resultCode == RESULT_OK)) {
            Bundle extras = data.getExtras();
            bmp = (Bitmap) extras.get("data");

            view2.setImageBitmap(bmp);
}
于 2013-03-18T09:03:56.603 回答
0
private String uploadFile() {
        String responseString = null;

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 75, bos);
        bitmap = Bitmap.createScaledBitmap(bitmap, 300, 300, true);
        byte[] data = bos.toByteArray();

        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(Apis.Base);


        try {
            AndroidMultiPartEntity entity = new AndroidMultiPartEntity(
                    new AndroidMultiPartEntity.ProgressListener() {

                        @Override
                        public void transferred(long num) {
                            publishProgress((int) ((num / (float) totalSize) * 100));
                        }
                    });


            ByteArrayBody bab = new ByteArrayBody(data, "bt.jpg");
            entity.addPart("gallery", bab);
            entity.addPart("action", new StringBody("update_photos"));
            entity.addPart("user_id", new StringBody(SaveSharedPreference.getUserID(GalleryFragment.this)));


            totalSize = entity.getContentLength();
            httppost.setEntity(entity);

            // Making server call
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity r_entity = response.getEntity();

            statusCode = response.getStatusLine().getStatusCode();
            responseString = EntityUtils.toString(r_entity);
            jsonObject = new JSONObject(responseString);
            Log.e("respon", "" + responseString);

            if (statusCode == 200) {
                // Server response
                SaveSharedPreference.setUserIMAGE(GalleryFragment.this, "https://pickpamphlet.com/PropertyApp/uploads/profile_pic/" + jsonObject.getJSONObject("data").getString("profile_pic"));

            } else if (statusCode == 201) {
                // Server response

                SaveSharedPreference.setUserIMAGE(GalleryFragment.this, "https://pickpamphlet.com/PropertyApp/uploads/profile_pic/" + jsonObject.getJSONObject("data").getString("profile_pic"));


            } else {
                responseString = "Error occurred! Http Status Code: " +
                        EntityUtils.toString(r_entity) + statusCode;
            }

        } catch (ClientProtocolException e) {
            responseString = e.toString();
        } catch (Exception e) {
            responseString = e.toString();
        }

        return responseString;
    }

制作一个类似这样的函数将图像上传到服务器并调整其大小。

于 2017-09-09T08:22:52.610 回答