【问题标题】:Compress photo taken by android camera before upload to server [duplicate]在上传到服务器之前压缩android相机拍摄的照片[重复]
【发布时间】:2013-10-31 15:16:05
【问题描述】:

我正在使用此代码将图像从 android 相机上传到服务器:

        miFoto = params[0];
        try { 
            HttpClient httpclient = new DefaultHttpClient();
            httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
            HttpPost httppost = new HttpPost("http://www.myserver.com/upload.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;

问题是文件太大。我已经尝试了一些在上传之前压缩图像的方法,但由于我是 android 的初学者,这对我来说是不可能的。

谢谢。

【问题讨论】:

    标签: android upload compression


    【解决方案1】:

    我想您可以将图像调整为较低的分辨率并重写文件,然后上传。调整大小的过程可以看这里。

    How to resize image (Bitmap) to a given size?

    【讨论】:

      猜你喜欢
      • 2017-10-01
      • 1970-01-01
      • 2012-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-25
      • 1970-01-01
      • 2018-01-19
      相关资源
      最近更新 更多