안드로이드 카메라 영상에 그림을 그린 후 저장하는 간단한 예제 코드 입니다.
"캐치미"에서 실제 사용한 코드입니당.
//카메라 영상이 담긴 rgb 데이터를 근간으로 Bitmap 생성 // rgb[] -> 카메라 데이터 // w -> 가로 사이즈 // w -> 세로 사이즈 Bitmap fg = Bitmap.createBitmap(rgb, w, h, Config.ARGB_8888); // i는 사각형을 그릴 기준 위치 (배열데이터 기준) Rect r = new Rect(); int x = i % w; int y = i / w; r.left = x - 90; r.top = y - 90; r.right = x + 90; r.bottom = y + 90; if(r.left < 0) r.left = 0; if(r.top < 0) r.top = 0; if(r.right > w) r.top = w; if(r.bottom > h) r.bottom = h; Bitmap bl = fg.copy(Config.ARGB_8888, true); Canvas canvas = new Canvas(); canvas.setBitmap(bl); Paint paint = new Paint(); paint.setStrokeWidth(3); //페인트 두께는 3픽셀 paint.setStyle(Style.STROKE); paint.setAntiAlias(true); paint.setColor(Color.RED); //빨간색으로- canvas.drawRect(r, paint); //사각형을 그린 후- Matrix matrix = new Matrix(); matrix.postRotate(rotateResult); Bitmap rotatedback = Bitmap.createBitmap(bl, 0, 0, w, h, matrix, true); // 이미지 회전 SaveToPNG(rotatedback); //bmp 를 받아 저장하는 함수 void SaveToPNG(Bitmap bitmap) { String mPath = Environment.getExternalStorageDirectory().getAbsolutePath(); try { FileOutputStream out = new FileOutputStream(mPath + "/mooda.png"); bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); } catch (FileNotFoundException e) { myText.setText("saveing error"); } }