【问题标题】:Get full quality picture from camera and upload?从相机获取全质量图片并上传?
【发布时间】:2013-02-26 01:33:55
【问题描述】:

我正在尝试让我的应用上传从手机摄像头拍摄的完整质量图像。我已经完成了整个上传工作,唯一的问题是生成的图像是一个非常小的位图。我很想获得完整质量的图像。谁能帮我?这是我的代码。

public class UploadActivity extends Activity {

    public final static int CAMERA_REQUEST = 1888;
    InputStream is;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_upload);
        Button takePicture = (Button) findViewById(R.id.take_picture_button);
        takePicture.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(takePictureIntent, CAMERA_REQUEST);      
            }
        });
        Button uploadButton = (Button) findViewById(R.id.send_button);
        uploadButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        ImageView mImageView = (ImageView) findViewById(R.id.ivUserImage);
        Bundle extras = data.getExtras();
        Bitmap mImageBitmap = (Bitmap) extras.get("data");
        mImageView.setImageBitmap(mImageBitmap);
        new fileUpload().execute(mImageBitmap);
    }

    public class fileUpload extends AsyncTask<Object, Void, Void> {
        @Override
        protected Void doInBackground(Object... param) {
            Bitmap bitmapOrg = (Bitmap) param[0];
            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));

            try {
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost("http://example.info/appserver/upload.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());
            }
            return null;
        }
    }
}

【问题讨论】:

  • 你能告诉我你是怎么解决这个质量问题的。我也用了同样的代码。。

标签: android image upload android-camera


【解决方案1】:

当你使用从额外读取位图时,你会得到图像的缩略图。

你可以在这里找到一个使用相机的好例子:https://stackoverflow.com/a/5071133/2045570

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-07
    • 2011-12-31
    • 2021-05-21
    相关资源
    最近更新 更多