我使用手機拍照相機應用程序來捕獲圖像。 實際上,這是來自android開發人員網站的示例代碼,介紹如何簡單地拍照,以及適合我應用需求的一些調整。Android - 如何在保存圖像之前對圖像進行水印處理
public void dispatchTakePictureIntent(int actionCode) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File f = null;
try {
f = setUpPhotoFile();
mCurrentPhotoPath = f.getAbsolutePath();
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
} catch (IOException e) {
e.printStackTrace();
f = null;
mCurrentPhotoPath = null;
}
startActivityForResult(takePictureIntent, actionCode);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mImageBitmap = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
mAlbumStorageDirFactory = new FroyoAlbumDirFactory();
} else {
mAlbumStorageDirFactory = new BaseAlbumDirFactory();
}
dispatchTakePictureIntent(ACTION_TAKE_PHOTO);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (mCurrentPhotoPath != null) {
Intent mediaScanIntent = new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE");
File f = new File(mCurrentPhotoPath);
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
this.sendBroadcast(mediaScanIntent);
mCurrentPhotoPath = null;
}
dispatchTakePictureIntent(ACTION_TAKE_PHOTO);
}
else{
finish();
}
}
和水印用字符串的位圖的方法。
public static Bitmap mark(Bitmap src, String watermark) {
int w = src.getWidth();
int h = src.getHeight();
Bitmap result = Bitmap.createBitmap(w, h, src.getConfig());
Canvas canvas = new Canvas(result);
canvas.drawBitmap(src, 0, 0, null);
Paint paint = new Paint();
paint.setColor(Color.RED);
paint.setTextSize(18);
paint.setAntiAlias(true);
paint.setUnderlineText(true);
canvas.drawText(watermark, 20, 25, paint);
return result;
}
問題是我無法獲得位圖使用此方法。
非常感謝提前!
創建從相機 – Praveen 2014-11-23 10:46:59
返回我可以將文件轉換F到的位圖,然後用標記方法的數據位圖,但在此之後,是什麼? – Vissarionas 2014-11-23 16:07:21
將其保存爲文件 – Praveen 2014-11-23 18:00:04