0

i have method to call camera activity,,but result from camera is big size, and i want to resize image in to small size..this is my method

public void startCamera() 
{

    fileName =helper.getKdStore(c)+"_"+System.currentTimeMillis()+ ".jpg";
    _path=Environment.getExternalStorageDirectory().toString() + "/Alfa Location/";

    file = new File(_path, fileName);
    try {
    file.createNewFile();
    } catch (IOException e) {
    e.printStackTrace();
    }               

    Uri outputFileUri = Uri.fromFile(file);
    Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
    startActivityForResult(intent, IMAGE_CAPTURE);

}

and this is activity result method

protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{
    if (requestCode == IMAGE_CAPTURE) 
    {
        if (resultCode == RESULT_OK)
        {
            Log.d("ANDRO_CAMERA","Picture taken!!!");
            //imageView.setImageURI(imageUri);
            Toast.makeText(Detail.this, "Gambar Berhasil di simpan", Toast.LENGTH_LONG).show();

        }
    }
 }

how i can resize image??thank you

akubabas
  • 473
  • 5
  • 13
  • 28

1 Answers1

2

You can change image size after giving from camera using

int desiredImageWidth = 100;  // pixels
int desiredImageHeight = 100; // pixels

BitmapFactory.Options o = new BitmapFactory.Options();
Bitmap newImage = Bitmap.createScaleBitmap(BitmapFactory.decodeFile(imagePath, o), 
                                           desiredImageWidth, 
                                           desiredImageHeight, 
                                           false);
Kayhan Asghari
  • 2,817
  • 1
  • 28
  • 47
  • @akubabas you put it where you do the `Toast`, where `imagePath` is the `URI` you put into the `Intent` (`outputFileUri` as you called it in your code. You probably want to make this a class variable). There are other good examples on SO of resizing images (this one for example: http://stackoverflow.com/questions/477572/android-strange-out-of-memory-issue/823966#823966). If you want to display the image or save the resized image see here: http://stackoverflow.com/questions/6027720/android-how-to-save-captured-image-into-phones-gallery – Salil Pandit Mar 12 '12 at 03:12