I am trying to get a bitmap from mobile vision's face tracking camera but after about 5 hours of trying, i am kind of stuck.
I. Firstly, Result: Blank image with
Bitmap image = mSurfaceView.getDrawingCache().
I already set true for SetDrawingCache in here:
public CameraSourcePreview(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
mStartRequested = false;
mSurfaceAvailable = false;
mSurfaceView = new SurfaceView(context);
mSurfaceView.getHolder().addCallback(new SurfaceCallback());
//HERE
mSurfaceView.setDrawingCacheEnabled(true);
addView(mSurfaceView);
}
II. After that i tried: Take screenshot of Graphic OVerlay, and get a shot from camera, then merge these 2 bitmap -> Result: Horrible. Everything need to be right is wrong.
If anyone can come up with any solutions( even suggestions are fine), i would be very appreciated.
Quan.
After 8 hours of trying. I get this workaround.
First, i get the overlay screenshot with it's X and Y in the facetracking camera:
overlay = screenShot(mGraphicOverlay);
final float overlayX = mGraphicOverlay.getX();
final float overlayY = mGraphicOverlay.getY();
Then i take a picture from the camera. Resize the overlay to fit the picture from the camera. After that i merge those 2 into 1 bitmap. And send it back to main activity.
mCameraSource.takePicture(null, new CameraSource.PictureCallback(){
@Override
public void onPictureTaken(byte[] bytes) {
//Bitmap loadedImage = null;
loaded = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
Bitmap rotatedBitmap = null;
Matrix rotateMatrix = new Matrix();
rotateMatrix.postRotate(90);
rotatedBitmap = Bitmap.createBitmap(loaded, 0, 0,
loaded.getWidth(), loaded.getHeight(),
rotateMatrix, false);
overlay = resize(overlay,rotatedBitmap.getWidth(), rotatedBitmap.getHeight());
merged = MergeBitmap(rotatedBitmap, overlay, overlayX, overlayY);
Intent myIntentA1A2 = new Intent(context, MainActivity.class);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
merged.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream .toByteArray();
String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
//imgDecodableString = BitMapToString(GlobalResource.glass);
myIntentA1A2.putExtra("Image", encoded);
context.startActivity(myIntentA1A2);