Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving bitmap to SD card with out compressing it in android

I am using android inbuilt camera to take picture and then attaching the same picture to email, when i am testing this functionality in 1.6 device, i am able name the picture that to be taken by in built camera, but in 2.1, the picture is having a name i.e given by device,

How to give user defined name in 2.1 inbuilt camera images..

to avoid that problem i am saving the image manually but when i try to get the image back through intent as bitmap and then saving it to sd card using compress method

this methods handles result from inbuilt camera

protected void onActivityResult(int requestCode, int resultCode, Intent data)
 {
  File file = new File(Environment.getExternalStorageDirectory()
    + "/test.png");
  switch (requestCode)
  {
  case PHOTO_ACTION:
   if (resultCode == RESULT_CANCELED)
   {
     addPhoto = false;
     Toast.makeText(this, "Canceled ", Toast.LENGTH_LONG).show();
     break;
   } else if (resultCode == RESULT_OK)
   {
    Bundle b = data.getExtras();
    Bitmap bm = (Bitmap) b.get("data");

    FileOutputStream out;
    try
     {

     out = new FileOutputStream(file);
     bm.compress(Bitmap.CompressFormat.JPEG, 100, out);
     out.flush();
     out.close();
     scanPhoto(file.toString());
     out = null;
     addPhoto = true;
     } catch (Exception e)
      {
       e.printStackTrace();
       addPhoto = false;
      }

but when i am storing like this i am getting two images. one with system given name and other with name given by me. but the image one which has user defined is having less resolution so i question is how to save the bitmap with more resolution with out compressing it .. please help.... me

like image 296
Ramesh Bugatha Avatar asked Oct 13 '10 12:10

Ramesh Bugatha


1 Answers

If you just want to save the bitmap without losing quality try using CompressFormat.PNG instead of JPEG, I've seen people having that problem before. Try changing:

bm.compress(Bitmap.CompressFormat.JPEG, 100, out);

with:

bm.compress(Bitmap.CompressFormat.PNG, 100, out);

and see it it helps.

like image 71
rjam Avatar answered Oct 12 '22 23:10

rjam