@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE) {
if (resultCode == RESULT_OK) {
try {
InputStream in = getContentResolver().openInputStream(data.getData());
img = BitmapFactory.decodeStream(in);
in.close();
img = resize(img);
imageView.setImageBitmap(img);
} catch (Exception e) {
}
}
}
}
imgCompress(img);
public void imgCompress(Bitmap img){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
img.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] bytes = baos.toByteArray();
image = Base64.encodeToString(bytes,Base64.DEFAULT);
}
private Bitmap resize(Bitmap img){
Configuration config=getResources().getConfiguration();
if(config.smallestScreenWidthDp>=800)
img = Bitmap.createScaledBitmap(img, 400, 240, true);
else if(config.smallestScreenWidthDp>=600)
img = Bitmap.createScaledBitmap(img, 300, 180, true);
else if(config.smallestScreenWidthDp>=400)
img = Bitmap.createScaledBitmap(img, 200, 120, true);
else if(config.smallestScreenWidthDp>=360)
img = Bitmap.createScaledBitmap(img, 180, 108, true);
else
img = Bitmap.createScaledBitmap(img, 160, 96, true);
return img;
}
}