0

I need for my Android application, take a picture of small size (> 1MB) with the camera. But I can not resize the file obtained with the camera and then save it to the phone. If someone has an idea to crop the photo or to ask the user to change camera settings.

thank you

  • maybe this help you http://stackoverflow.com/questions/10325158/android-camera-activity-gets-opened-instead-of-picture-gallery/10326395#10326395 – MichaelP May 07 '12 at 09:34

3 Answers3

2

Once you have the bitmap write it to a file using

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();
sachy
  • 739
  • 7
  • 13
  • thank's, but how have a file with a bitmap ? How transform "yourBmp" in File ? – Romain Daquin May 07 '12 at 10:02
  • the above code snippet is doing it. The line yourBmp.compress(BItmap.CompressFormat.JPG, 80, out); will write your bmp file into the file "imageFile" that you have created – sachy May 07 '12 at 10:04
  • +1 i would go with this solution if i want to compress the image. – Paresh Mayani May 07 '12 at 10:11
  • 1
    Please, how write bmp into the file ? And how save the file changes ? – Romain Daquin May 07 '12 at 11:23
  • Seriously you have everything in front of you and you are still asking. Have you even tried the code snippet?? – sachy May 07 '12 at 11:32
  • File imageFile = new File(pathToOurFile); OutputStream out = null; out = new FileOutputStream(imageFile); BitmapFactory.Options bmOptions = new BitmapFactory.Options(); Bitmap bitmap = BitmapFactory.decodeFile(pathToOurFile, bmOptions); bitmap.compress(Bitmap.CompressFormat.JPEG,80,out); out.flush(); out.close(); imageFile.createNewFile(bitmap); //Error FileInputStream fileInputStream = new FileInputStream(imageFile); – Romain Daquin May 07 '12 at 11:39
  • Why are u creating a new file "imageFile.createNewFile(bitmap);" when your already have created one. And plz do not forget to put this code in try catch block – sachy May 07 '12 at 11:46
  • this line bitmap.compress(Bitmap.CompressFormat.JPEG,80,out); don't work ... When to comment this line, my program work. – Romain Daquin May 07 '12 at 12:01
  • @RomainDaquin first thing that you have to do is to get the bitmap and than using the given code snippet you can write it into your phone as a file(.jpg file in this case). I hope you are getting bitmap correctly – sachy May 07 '12 at 12:17
  • 1
    I have an exception with my code : java.lang.NullPointerException My function is below – Romain Daquin May 09 '12 at 09:29
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());
    }
0

If you can take the picture, you probably have it's name. Then you could simply open up the image again and resize the image, see http://www.anddev.org/resize_and_rotate_image_-_example-t621.html

Thkru
  • 4,218
  • 2
  • 18
  • 37
  • yes I have the address of the file, I can create a bitmap but how to save the new bitmap file so I can send it on a ftp server? – Romain Daquin May 07 '12 at 09:32
  • just use the code of sachy's post to resize your image, then use http://stackoverflow.com/questions/10479333/android-ftp-a-file-from-device-to-a-server/10479680#comment13541336_10479680 to upload it to a ftp! – Thkru May 07 '12 at 09:42
  • but after resize, i have a bitmap type not a file type, it's a problem. I need a file for to send in the server. – Romain Daquin May 07 '12 at 09:55
  • http://www.roseindia.net/java/beginners/java-write-to-file.shtml you can simply write this bitmap to a file again – Thkru May 07 '12 at 10:59