I did browse through the entire network prior to publication. My problem is that I cannot resize a bitmap image without losing image quality (the quality is really poor and uneven).
I accept a bitmap from the camera, and then I need to scale it, so I can upload it to the server much faster.
This is the function that performs the selection.
public Bitmap resizeBitmap(Bitmap bitmap){ Canvas canvas = new Canvas(); Bitmap resizedBitmap = null; if (bitmap !=null) { int h = bitmap.getHeight(); int w = bitmap.getWidth(); int newWidth=0; int newHeight=0; if(h>w){ newWidth = 600; newHeight = 800; } if(w>h){ newWidth = 800; newHeight = 600; } float scaleWidth = ((float) newWidth) / w; float scaleHeight = ((float) newHeight) / h; Matrix matrix = new Matrix();
and this is how I get the image from the activity result
protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(resultCode != RESULT_CANCELED){ if (requestCode == 0) { if (resultCode == RESULT_OK) { getContentResolver().notifyChange(mImageUri, null); ContentResolver cr = this.getContentResolver(); try { b = android.provider.MediaStore.Images.Media.getBitmap(cr, mImageUri); Log.d("foto", Integer.toString(b.getWidth())); Log.d("foto", Integer.toString(b.getHeight())); addPhoto.setImageBitmap(b); } catch (Exception e) { Toast.makeText(this, "Failed to load", Toast.LENGTH_SHORT).show(); Log.d("TAG", "Failed to load", e); } } }
I'm starting to think that the best way to get a small image size is to set the camera resolution. Can anybody help?
source share