0
我試圖捕獲圖像,並從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個或更多的百萬像素CAMER,我得到out of memory
厚望。也許有人可以幫我解決這個問題?
我試圖做你喜歡說,它幾乎不錯,但我有另一個問題 [鏈接] http://www.part.lt/img/eb4e149bc162f8ce4ccb9249fd1ca22c384.jpg,whatch圖片,得到一個正常的圖片和它的另一個1/2更小。 :) – Justinas 2013-05-14 06:43:28
好吧,解決了這個問題,另一個最後一個!然後我捕捉圖像並保存,它改變方向。 – Justinas 2013-05-14 10:52:16