, Toast.LENGTH_SHORT).show();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
}
@Override
protected void onActivityResult(
int requestCode,
int resultCode, Intent data) {
// TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data);
if (resultCode ==
RESULT_OK) {
Uri imageFileUri =
data.getData();
Display display =
getWindowManager().getDefaultDisplay();
float dw =
display.getWidth();
float dh =
display.getHeight();
try {
BitmapFactory.Options options =
new BitmapFactory.Options();
options.inJustDecodeBounds =
true;
bitmap =
BitmapFactory.decodeStream(getContentResolver()
.openInputStream(imageFileUri), null, options);
int heightRatio = (
int) Math.ceil(options.outHeight /
dh);
int widthRatio = (
int) Math.ceil(options.outWidth /
dw);
if (heightRatio > 1 && widthRatio > 1
) {
if (heightRatio >
widthRatio) {
options.inSampleSize =
heightRatio;
} else {
options.inSampleSize =
widthRatio;
}
}
options.inJustDecodeBounds =
false;
bitmap =
BitmapFactory.decodeStream(getContentResolver()
.openInputStream(imageFileUri), null, options);
alterBitmap =
Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), bitmap.getConfig());
canvas =
new Canvas(alterBitmap);
paint =
new Paint();
paint.setColor(Color.GREEN);
paint.setStrokeWidth(10
);
Matrix matrix =
new Matrix();
canvas.drawBitmap(bitmap, matrix, paint);
image.setImageBitmap(alterBitmap);
image.setOnTouchListener(this);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
}
效果: