我正试图从移动视觉的面部跟踪相机获得一个位图,但经过大约5个小时的尝试,我有点卡住了。
一.第一,结果:空白图像
Bitmap image = mSurfaceView.getDrawingCache(). 我已经在这里为SetDrawingCache设置了真:
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);
}在那之后,我试着:拍摄图片OVerlay的截图,并从相机中获得一个截图,然后合并这两个位图->结果:可怕。一切都必须是对的是错的。
如果有人能想出任何解决方案(甚至建议都可以),我将非常感激。
泉。
发布于 2016-12-08 03:10:00
经过8个小时的尝试。我能解决这个问题。
首先,我得到了覆盖屏幕截图与它的X和Y在脸跟踪相机:
overlay = screenShot(mGraphicOverlay);
final float overlayX = mGraphicOverlay.getX();
final float overlayY = mGraphicOverlay.getY();然后我从相机里拍了张照片。调整覆盖层的大小,以适应相机的图片。在此之后,我将这2合并成1位图。然后把它送回主要活动。
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);https://stackoverflow.com/questions/41022931
复制相似问题