Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 图像压缩不工作_Android_Image_Amazon S3_Imageview_Image Compression - Fatal编程技术网

Android 图像压缩不工作

Android 图像压缩不工作,android,image,amazon-s3,imageview,image-compression,Android,Image,Amazon S3,Imageview,Image Compression,我正在尝试使用相机上传图片。我正在把它上传到服务器上 单击图像并在imageview中显示(完成) 压缩要上载的图像大小(不工作) 将图像上载到S3(带有未压缩图像)(完成) 这是我的onActivityResult() 复制logcat并粘贴到这里(编辑您的答案)也许这个链接可以帮助您:“压缩图像大小以上传”???你想做什么?压缩或调整大小?@greenapps我想捕获一张图像,并在压缩后上传。压缩.jpg文件没有意义,因为它已经压缩好了。 case CAMERA_REQUEST:

我正在尝试使用相机上传图片。我正在把它上传到服务器上

  • 单击图像并在imageview中显示(完成)
  • 压缩要上载的图像大小(不工作)
  • 将图像上载到S3(带有未压缩图像)(完成)

    这是我的onActivityResult()



  • 复制logcat并粘贴到这里(编辑您的答案)也许这个链接可以帮助您:“压缩图像大小以上传”???你想做什么?压缩或调整大小?@greenapps我想捕获一张图像,并在压缩后上传。压缩.jpg文件没有意义,因为它已经压缩好了。
        case CAMERA_REQUEST: {
    
            Uri selectedImage = data.getData();
            String[] filePathColumn = { MediaStore.Images.Media.DATA };
    
            Cursor cursor = getContentResolver().query(selectedImage,
                    filePathColumn, null, null, null);
            cursor.moveToFirst();
    
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String picturePath = cursor.getString(columnIndex);
            cursor.close();
    
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            BitmapFactory.decodeFile(picturePath, options);
            int imageHeight = options.outHeight;
            int imageWidth = options.outWidth;
            String imageType = options.outMimeType;
                options.inSampleSize = calculateInSampleSize(options,200,100);//512 and 256 whatever you want as scale
                options.inJustDecodeBounds = false;
            Bitmap yourSelectedImage = BitmapFactory.decodeFile(picturePath,options);
    
            File pngDir = new   File(Environment.getExternalStorageDirectory(),"PicUploadTemp");
            if (!pngDir.exists()) {
                pngDir.mkdirs();
                }
    
          File pngfile = new File(pngDir,"texture1.jpg");
            FileOutputStream fOut;
    
            try {
                    fOut = new FileOutputStream(pngfile);
    
                     yourSelectedImage.compress(Bitmap.CompressFormat.JPEG, 50,fOut);
    
    
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            Drawable d = Drawable.createFromPath(pngfile.getPath().toString());
            rlLayout.setBackground(d);
    
            yourSelectedImage.recycle();
        //    resizedBitmap.recycle();
    
            xfile = pngfile; 
        }
        break;
    
    cam.setOnClickListener(new OnClickListener() {
    
                    @Override
                    public void onClick(View v) {
                        Intent cameraIntent = new Intent(
                                android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                        startActivityForResult(cameraIntent, CAMERA_REQUEST);
                    }
                });