My application accesses the camera and captures the picture then saves it back in sdcard.
The problem is that image is quite big around 1500X2500 px and 500kb in size. I have to upload the image to server. So I thought of editing the image but I want to edit the image in correct composition i.e. correct height:width ratio so that image doesn't looks oddThe code which I am using:
FileInputStream in = new FileInputStream("/mnt/sdcard/DCIM/1302779969138");
BufferedInputStream buf = new BufferedInputStream(in)
Bitmap bm = BitmapFactory.decodeStream(buf);
File isfile = new File(Environment.getExtern开发者_如何学JAVAalStorageDirectory(),"/DCIM/1302779969138");
FileOutputStream fout = new FileOutputStream(isfile);
Bitmap bitmap = null;
bitmap = Bitmap.createScaledBitmap(bm, 350, 350, true);
bitmap.compress(CompressFormat.JPEG, 20, fout);
With the above code I am able to resize the image to 350 X 350 but iI wish to scale it with only width as a parameter so that height adjusts accordingly and the image ratio remains the same
Plus also mention if I should be flushing Fileoutputsteam
and inputStream
How to scale an image preserving its aspect ratio:
orig_width = bm.getWidth();
orig_height = bm.getHeight();
aspect = orig_width / orig_height;
new_width = 500;
new_height = orig_height / aspect;
or
new_height = 500;
new_width = orig_width * aspect;
精彩评论