COM preSS上传前摄像头图像 [英] Compress camera image before upload

查看:110
本文介绍了COM preSS上传前摄像头图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用这code(从<一个href="http://www.internetria.com/blog/2013/04/12/android-enviar-imagenes-por-webservice/">www.internetria.com)拍摄照片并上传到服务器:

I am using this code (from www.internetria.com) to take a photo and upload to a server:

的onCreate:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri output = Uri.fromFile(new File(foto));
intent.putExtra(MediaStore.EXTRA_OUTPUT, output);
startActivityForResult(intent, TAKE_PICTURE);

onActivityResult:

onActivityResult:

ImageView iv = (ImageView) findViewById(R.id.imageView1);
        iv.setImageBitmap(BitmapFactory.decodeFile(foto));

        File file = new File(foto);
        if (file.exists()) {
            UploaderFoto nuevaTarea = new UploaderFoto();
            nuevaTarea.execute(foto);
        }
        else
            Toast.makeText(getApplicationContext(), "No se ha realizado la foto", Toast.LENGTH_SHORT).show();

UploaderFoto:

UploaderFoto:

ProgressDialog pDialog;
String miFoto = "";

@Override
protected Void doInBackground(String... params) {
    miFoto = params[0];
    try { 
        HttpClient httpclient = new DefaultHttpClient();
        httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
        HttpPost httppost = new HttpPost("http://servidor.com/up.php");
        File file = new File(miFoto);
        MultipartEntity mpEntity = new MultipartEntity();
        ContentBody foto = new FileBody(file, "image/jpeg");
        mpEntity.addPart("fotoUp", foto);
        httppost.setEntity(mpEntity);
        httpclient.execute(httppost);
        httpclient.getConnectionManager().shutdown();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

和我想的COM preSS的形象,因为规模过大。

And I want to compress the image, because the size is too big.

我不知道如何添加 bitmap.com preSS(Bitmap.Com pressFormat.JPEG,70,FOS); 来我的应用程序

I don't know how to add bitmap.compress(Bitmap.CompressFormat.JPEG, 70, fos); to my app

推荐答案

看看在这里:<一href="http://stackoverflow.com/questions/7832598/bytearrayoutputstream-to-a-filebody">ByteArrayOutputStream到FileBody

这些方针的东西应该工作:

Something along these lines should work:

替换

File file = new File(miFoto);
ContentBody foto = new FileBody(file, "image/jpeg");

Bitmap bmp = BitmapFactory.decodeFile(miFoto)
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bmp.compress(CompressFormat.JPEG, 70, bos);
InputStream in = new ByteArrayInputStream(bos.toByteArray());
ContentBody foto = new InputStreamBody(in, "image/jpeg", "filename");

如果文件大小仍然可能要的图片,除了扩展到COM pressing这是一个问题。

If file size is still an issue you may want to scale the picture in addition to compressing it.

这篇关于COM preSS上传前摄像头图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆