1. Are you ready for the Galaxy S20? Here is everything we know so far!

creating jpeg file in internal storage

Discussion in 'Android Development' started by asthasharma017, Aug 14, 2012.

  1. asthasharma017

    Thread Starter

    Hello,
    I am writing a code for an android app in which I have to captures image and save it into internal storage of android. For this I have written the following code-
    Code (Text):
    1.  
    2. Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    3.                     String newPath = PATH+"/"+folderName+"/"+imageName+".jpg";
    4.                     File file = new File( newPath );
    5.                     file.mkdirs();
    6.                     Uri outputFileUri = Uri.fromFile( file );
    7.                     intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
    8.                     startActivityForResult(intent, 0);
    9.  
    This code creates jpeg file but don't write the image into it.
    Later I tried writing following code in onActivityResult-
    Code (Text):
    1.  
    2.  protected void onActivityResult(int requestCode, int resultCode, Intent data)
    3.     {
    4. Bitmap bitmap = (Bitmap) data.getExtras().get("data");
    5.                     ByteArrayOutputStream bos = new ByteArrayOutputStream();
    6.                     bitmap.compress(CompressFormat.PNG, 0, bos);
    7.                     byte[] bitmapdata = bos.toByteArray();
    8.                     File file = new File( newPath );
    9.                 FileOutputStream fos = new FileOutputStream(file);
    10.                 fos.write(bitmapdata);
    11. }
    12.  
    But its still not working. Please help...
     



    1. Download the Forums for Android™ app!


      Download

       
  2. jonbonazza

    jonbonazza Android Expert

    Moved to App Dev. =)
     
Loading...
Similar Threads - creating jpeg file
  1. soulartist
    Replies:
    14
    Views:
    568
  2. Relaxing Leg
    Replies:
    0
    Views:
    450
  3. Sajivjess
    Replies:
    1
    Views:
    525
  4. RicardoM
    Replies:
    1
    Views:
    553
  5. My project
    Replies:
    9
    Views:
    746
  6. grizmixstir
    Replies:
    3
    Views:
    1,050
  7. kdmoore
    Replies:
    3
    Views:
    1,181
  8. cwg01
    Replies:
    3
    Views:
    2,903
  9. kumaranil13k
    Replies:
    4
    Views:
    1,132
  10. 5g Moto Android 11
    Replies:
    2
    Views:
    2,341

Share This Page

Loading...