Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.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 studio_Android_Android Camera Intent_Image Size - Fatal编程技术网

保存全尺寸图像android studio

保存全尺寸图像android studio,android,android-camera-intent,image-size,Android,Android Camera Intent,Image Size,我试图将全尺寸图像保存到数据库中,但应用程序保存的图像比我用相机拍摄的原始图像最小。以下是onActivityResult的方法: case TAKE_AVATAR_CAMERA_REQUEST_DOCUMENTO: case TAKE_AVATAR_CAMERA_REQUEST_INFRACCION: if (resultCode == Activity.RESULT_CANCELED) { // Avatar came

我试图将全尺寸图像保存到数据库中,但应用程序保存的图像比我用相机拍摄的原始图像最小。以下是onActivityResult的
方法:

case TAKE_AVATAR_CAMERA_REQUEST_DOCUMENTO:
        case TAKE_AVATAR_CAMERA_REQUEST_INFRACCION:

            if (resultCode == Activity.RESULT_CANCELED) {
                // Avatar camera mode was canceled.
            } else if (resultCode == Activity.RESULT_OK) {

                // Took a picture, use the downsized camera image provided by
                // default
                Bitmap cameraPic = (Bitmap) data.getExtras().get("data");
                if (cameraPic != null) {
                    try {


                        saveAvatar(cameraPic, requestCode);
                    } catch (Exception e) {
                        Log.e(DEBUG_TAG, "saveAvatar() with camera image failed.", e);
                    }
                }
            }
            break;


private void saveAvatar(Bitmap avatar, int pRequestCode) {
        String strAvatarFilename = "avatar.jpg";
        String sPreferenceFoto = GAME_PREFERENCES_AVATAR;
        String sNumeroActa = (new ActaConstatacionRules(this)).getNextNumeroActa();
        int _idButton = 0;
        switch (pRequestCode) {
        case TAKE_AVATAR_CAMERA_REQUEST_LICENCIA:
            strAvatarFilename = sNumeroActa + "_licencia.jpg";
            sPreferenceFoto = CURRENT_ACTA_FOTO_LICENCIA;
            _idButton = R.id.ImageButton_Licencia;
            break;
        case TAKE_AVATAR_CAMERA_REQUEST_DOCUMENTO:
            strAvatarFilename = sNumeroActa + "_documento.jpg";
            sPreferenceFoto = CURRENT_ACTA_FOTO_DOCUMENTO;
            _idButton = R.id.ImageButton_Documento;
            break;
        case TAKE_AVATAR_CAMERA_REQUEST_INFRACCION:
            strAvatarFilename = sNumeroActa + "_infraccion.jpg";
            sPreferenceFoto = CURRENT_ACTA_FOTO_INFRACCION;
            _idButton = R.id.ImageButton_Infraccion;
            break;
        default:
            Utilities.ShowToast(this, "Seleccion de Imagen Invalida");
            return;
        }
        File image = null;
        try {

            File sdCardDirectory = Environment.getExternalStorageDirectory();
            image = new File(sdCardDirectory, strAvatarFilename);
            FileOutputStream outStream;

            try {

                outStream = new FileOutputStream(image);
                avatar.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
                /* 100 to keep full quality of the image */

                outStream.flush();
                outStream.close();

            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }



        } catch (Exception e) {
            Log.e(DEBUG_TAG, "Avatar compression and save failed.", e);
        }
 strAvatarFilename));
        if (image == null)
            return;
        Uri imageUriToSaveCameraImageTo = Uri.fromFile(image);

        Editor editor = mCurrenActaSettings.edit();
        editor.putString(sPreferenceFoto, imageUriToSaveCameraImageTo.getPath());
        editor.commit();

        // Update the settings screen
        ImageButton avatarButton = (ImageButton) findViewById(_idButton);
        String strAvatarUri = mCurrenActaSettings.getString(sPreferenceFoto, RESOURCE_SIN_FOTO);
        Uri imageUri = Uri.parse(strAvatarUri);
        avatarButton.setImageURI(null); // Workaround for refreshing an
                                        // ImageButton, which tries to cache the
                                        // previous image Uri. Passing null
                                        // effectively resets it.
        avatarButton.setImageURI(imageUri);
    }

我需要知道如何保存(例如)600 x 600的图像大小但不丢失质量,现在它可以保存200 x 100,但我不知道为什么。

您没有发布发送动作图像捕获意图的代码,但底线是,如果您返回
getExtras().get(“数据”)
,它是一个小缩略图。完整大小的图像已写入文件,您可以在需要时阅读。非常感谢您的回复,抱歉延迟,我理解您的意思,但如何获取完整大小的图像,以便设置imageview并将其以完整大小保存在数据库中。我将指向您问题答案的链接放在下面:
public File saveBitmapToFile(File file) {
    try {

        // BitmapFactory options to downsize the image
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        options.inSampleSize = 6;
        // factor of downsizing the image

        FileInputStream inputStream = new FileInputStream(file);
        //Bitmap selectedBitmap = null;
        BitmapFactory.decodeStream(inputStream, null, options);
        inputStream.close();
        inputStream = null;

        int originalWidth = options.outWidth;
        int originalHeight = options.outHeight;

        if (originalWidth > 0) {

            int reqWidth = 600;
            int reqHeight = (reqWidth * originalHeight) / originalWidth;
            if (reqHeight >= 600)
                reqHeight = 600;
            Log.d("new image ", "getDropboxIMGSize: " + reqHeight + "    " + 
 reqWidth);
            // decode full image pre-resized
            inputStream = new FileInputStream(file);
            options = new BitmapFactory.Options();

            // calc rought re-size (this is no exact resize)
            options.inSampleSize = Math.max(originalWidth / reqWidth, originalHeight 
 / reqHeight);
            // decode full image
            Bitmap roughBitmap = BitmapFactory.decodeStream(inputStream, null, 
 options);

            // calc exact destination size
            Matrix m = new Matrix();
            RectF inRect = new RectF(0, 0, roughBitmap.getWidth(), 
 roughBitmap.getHeight());
            RectF outRect = new RectF(0, 0, reqWidth, reqHeight);
            m.setRectToRect(inRect, outRect, Matrix.ScaleToFit.CENTER);
            float[] values = new float[9];
            m.getValues(values);

            // resize bitmap
            Bitmap resizedBitmap = Bitmap.createScaledBitmap(roughBitmap,
                    (int) (roughBitmap.getWidth()*values[0]),
            (int) (roughBitmap.getHeight()*values[4]),true);

            // override resized bitmap image
            file.createNewFile();
            FileOutputStream out = new FileOutputStream(file);
            resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 70, out);
        }
        return file;

    } catch (IOException e) {
        Log.e("Image", e.getMessage(), e);
        return null;
    }
  }