onActivityResult
我尝试从我的代码中捕获图像并从方法中设置水印。
Private void savingCapturedImage() {
long date = System.currentTimeMillis();
Date data = new Date(date);
File file = new File(Environment.getExternalStorageDirectory() + "/DCIM/Camera", "mobiliskaita.JPG");
Uri imagePath = Uri.fromFile(file);
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imagePath);
System.out.println("bitmap: " + bitmap.getWidth() + " " + bitmap.getHeight());
file.delete();
bitmap = mark(bitmap, String.valueOf(data), 100, 200, 100, false);
bitmap = mark(bitmap, TheGlobals.partneriaiValue, 100, 310, 100, false);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
bitmap.recycle();
File fileOutput = new File(Environment.getExternalStorageDirectory() + "/DCIM/Camera", photoName());
fileOutput.createNewFile();
FileOutputStream fo = new FileOutputStream(fileOutput);
fo.write(bytes.toByteArray());
fo.flush();
fo.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
private Bitmap mark(Bitmap src, String watermark, int x, int y, int size, boolean underline) {
int w = src.getWidth();
int h = src.getHeight();
Point _p = new Point();
_p.x = x;
_p.y = y;
final float scale = getResources().getDisplayMetrics().density;
int p = (int) (900 * scale + 0.5f);
Bitmap result = Bitmap.createScaledBitmap(src, p, p, true);
Canvas canvas = new Canvas(result);
canvas.drawBitmap(src, 0, 0, null);
Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setTextSize(R.dimen.default_text_size);
paint.setAntiAlias(true);
paint.setUnderlineText(underline);
canvas.drawText(watermark, _p.x, _p.y, paint);
return result;
}
它正在工作,但我有 8 或更多百万像素的相机,我out of memory
期待。也许有人可以帮助我解决这个问题?