Android - 拍小照片

时间:2012-05-07 09:19:53

标签: android camera resize image

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

谢谢

3 个答案:

答案 0 :(得分: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();

答案 1 :(得分: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());
    }

答案 2 :(得分:0)

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