これは、サイズを縮小するための唯一の解決策です。
public void onActivityResult(int requestcode, int resultcode, Intent data) {
if (resultcode == RESULT_OK) {
if (requestcode == SELECT_PICTURE) {
Uri uri = data.getData();
String imagePath = getPath(uri);
int SCALE = 2;
try{
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = SCALE;
Bitmap bitmap= BitmapFactory.decodeFile(imagePath, o2);
OutputStream os = new FileOutputStream(imagePath);
bitmap.compress(Bitmap.CompressFormat.PNG, 85, os);
os.flush();
os.close();
File file = new File(imagePath);
Log.i("Bitmap", "Height Width "+bitmap.getHeight()+" "+bitmap.getWidth());
Log.i("File","Size in bytes "+file.length());
while(file.length()>100*1024)
{
SCALE +=2;
o2.inSampleSize = SCALE;
bitmap= BitmapFactory.decodeFile(imagePath, o2);
os = new FileOutputStream(imagePath);
bitmap.compress(Bitmap.CompressFormat.PNG, 85, os);
os.flush();
os.close();
file = new File(imagePath);
Log.i("Bitmap", "Height Width "+bitmap.getHeight()+" "+bitmap.getWidth());
Log.i("File","Size in bytes "+file.length());
}
bitmap = BitmapFactory.decodeFile(imagePath, o2);
}
catch (Exception e) {
e.printStackTrace();
}
txtimagepath.setText(imagePath);
}
}
}
protected String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int columnIndex = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(columnIndex);
}