0

我需要为我的 Android 应用程序,用相机拍摄一张小尺寸 (> 1MB) 的照片。但是我无法调整用相机获得的文件的大小,然后将其保存到手机中。如果有人想裁剪照片或要求用户更改相机设置。

谢谢你

4

3 回答 3

2

获得位图后,使用

File imageFile = new File(pathToSaveYourNewFile, whateverNameForNewSmallPicture.jpg);
OutputStream out = null;
out = new FileOutputStream(imageFile);
yourBitmapFromTheOriginalFile.compress(Bitmap.CompressFormat.JPG, 80, out);
out.flush();
out.close();
于 2012-05-07T09:40:55.340 回答
1
/* Set bitmap options to scale the image decode target */
    bmOptions.inJustDecodeBounds = false;
    bmOptions.inSampleSize = scaleFactor;
    bmOptions.inPurgeable = true;

    /* Decode the JPEG file into a Bitmap */
    Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);

    /* Test compress */
    File imageFile = new File(picturePath);
    try{
        OutputStream out = null;
        out = new FileOutputStream(imageFile);
        //Bitmap bitmap = BitmapFactory.decodeFile(picturePath);

        bitmap.compress(Bitmap.CompressFormat.JPEG,80,out);
        out.flush();
        out.close();
    }catch(Exception e){
        Log.e("Dak","Erreur compress : "+e.toString());
    }
于 2012-05-09T12:24:54.583 回答
0

如果你能拍照,你可能知道它的名字。然后您可以简单地再次打开图像并调整图像大小,请参阅http://www.anddev.org/resize_and_rotate_image__-_example-t621.html

于 2012-05-07T09:26:45.810 回答