I am taking photo using in-built Camera App, and getting resolution of image (1600 x 1200) but I would like to save my all images in (1200 x 900) into SD Card for that I have written a method but still getting images in original size.
Here is my code, which I am using to capture and store images into SD Card
public class FormActivity extends AppCompatActivity {
String filePath = null;
File file;
Uri output;
final int requestCode = 100;
String stringImageName= null;
static int w = 1200;
static int h = 900;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_form);
SimpleDateFormat s = new SimpleDateFormat("ddMMyyyyhhmmss");
stringImageName = s.format(new Date());
Log.d("format::", stringImageName);
filePath = Environment.getExternalStorageDirectory() + "/"+stringImageName+".jpeg";
file = new File(filePath);
output = Uri.fromFile(file);
buttonOrderNow.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent photoCaptureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
photoCaptureIntent.putExtra(MediaStore.EXTRA_OUTPUT, output);
startActivityForResult(photoCaptureIntent, requestCode);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(this.requestCode == requestCode && resultCode == RESULT_OK) {
resize();
}
}
private void resize() {
Long startTime = System.currentTimeMillis();
Bitmap bitmap_Source = BitmapFactory.decodeFile(filePath);
float factorH = h / (float)bitmap_Source.getHeight();
float factorW = w / (float)bitmap_Source.getWidth();
float factorToUse = (factorH > factorW) ? factorW : factorH;
Bitmap bm = Bitmap.createScaledBitmap(bitmap_Source,
(int) (bitmap_Source.getWidth() * factorToUse),
(int) (bitmap_Source.getHeight() * factorToUse),
false);
Long endTime = System.currentTimeMillis();
Long processTime = endTime - startTime;
Toast.makeText(FormActivity.this, ""+processTime, Toast.LENGTH_LONG).show();
}