安卓 - 拍一张小照片



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

谢谢

一旦你让位图把它写到一个文件中,使用

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();
/* 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());
    }

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

最新更新