public override void draw(android.graphics.Canvas canvas) { if (((int)(((uint)mState.mUseColor) >> 24)) != 0) { mPaint.setColor(mState.mUseColor); canvas.drawRect(getBounds(), mPaint); } }
public override void draw(android.graphics.Canvas canvas) { android.graphics.Bitmap bitmap = mBitmap; if (bitmap != null) { android.graphics.drawable.BitmapDrawable.BitmapState state = mBitmapState; if (state.mRebuildShader) { android.graphics.Shader.TileMode?tmx = state.mTileModeX; android.graphics.Shader.TileMode?tmy = state.mTileModeY; if (tmx == null && tmy == null) { state.mPaint.setShader(null); } else { state.mPaint.setShader(new android.graphics.BitmapShader(bitmap, tmx == null ? android.graphics.Shader.TileMode .CLAMP : tmx, tmy == null ? android.graphics.Shader.TileMode.CLAMP : tmy)); } state.mRebuildShader = false; copyBounds(mDstRect); } android.graphics.Shader shader = state.mPaint.getShader(); if (shader == null) { if (mApplyGravity) { int layoutDirection = getResolvedLayoutDirectionSelf(); android.view.Gravity.apply(state.mGravity, mBitmapWidth, mBitmapHeight, getBounds (), mDstRect, layoutDirection); mApplyGravity = false; } canvas.drawBitmap(bitmap, null, mDstRect, state.mPaint); } else { if (mApplyGravity) { copyBounds(mDstRect); mApplyGravity = false; } canvas.drawRect(mDstRect, state.mPaint); } } }
public override void draw(android.graphics.Canvas canvas) { android.graphics.Rect r = getBounds(); android.graphics.Paint paint = mShapeState.mPaint; int prevAlpha = paint.getAlpha(); paint.setAlpha(modulateAlpha(prevAlpha, mShapeState.mAlpha)); if (mShapeState.mShape != null) { // need the save both for the translate, and for the (unknown) Shape int count = canvas.save(); canvas.translate(r.left, r.top); onDraw(mShapeState.mShape, canvas, paint); canvas.restoreToCount(count); } else { canvas.drawRect(r, paint); } // restore paint.setAlpha(prevAlpha); }
protected internal override void onDraw(Canvas canvas) { // Setup gravity. if ((mGravity & GRAVITY_START) > 0) { mRect.set(0, mRect.top, mRect.width(), mRect.bottom); } else if ((mGravity & GRAVITY_TOP) > 0) { mRect.set(mRect.left, 0, mRect.right, mRect.height()); } else if ((mGravity & GRAVITY_END) > 0) { mRect.set(canvas.Width - mRect.width(), mRect.top, canvas.Width, mRect.bottom); } else if ((mGravity & GRAVITY_BOTTOM) > 0) { mRect.set(mRect.left, canvas.Height - mRect.height(), mRect.right, canvas.Height); } if ((mGravity & GRAVITY_CENTER) > 0) { mRect.set((canvas.Width / 2) - (mRect.width() / 2), (canvas.Height / 2) - (mRect.height() / 2), (canvas.Width / 2) - (mRect.width() / 2) + mRect.width(), (canvas.Height / 2) - (mRect.height() / 2) + mRect.height()); } else if ((mGravity & GRAVITY_CENTER_HORIZONTAL) > 0) { mRect.set((canvas.Width / 2) - (mRect.width() / 2), mRect.top, (canvas.Width / 2) - (mRect.width() / 2) + mRect.width(), mRect.bottom); } else if ((mGravity & GRAVITY_CENTER_VERTICAL) > 0) { mRect.set(mRect.left, (canvas.Height / 2) - (mRect.height() / 2), mRect.right, (canvas.Height / 2) - (mRect.height() / 2) + mRect.height()); } // Merge offset. mRect.offset(mOffset.x, mOffset.y); canvas.drawRect(mRect, mPaint); }
protected internal override void onDraw(Canvas canvas) { if (mFaces != null && mZoomRect != null) { // Prepare matrix mMatrix.reset(); mAspectRatio.reset(); mActualRect.set(0, 0, mPreviewSize.Width, mPreviewSize.Height); // First apply zoom (crop) rect. // Unlike the documentation, many device does not report final crop region. // So, here we calculate final crop region which takes account aspect ratio between crop region and preview size. { mRevisionZoomRect.set(mZoomRect); float left = mRevisionZoomRect.left; float top = mRevisionZoomRect.top; mRevisionZoomRect.offsetTo(0, 0); mAspectRatio.setRectToRect(mActualRect, mRevisionZoomRect, Matrix.ScaleToFit.CENTER); mAspectRatio.mapRect(mActualRect); mActualRect.offset(left, top); } mMatrix.postTranslate(-mActualRect.centerX(), -mActualRect.centerY()); // compensate mirror mMatrix.postScale(mFacing == SCameraCharacteristics.LENS_FACING_FRONT ? -1 : 1, 1); // Then rotate and scale to UI size mMatrix.postRotate(mRotation); if (mOrientation == Configuration.ORIENTATION_LANDSCAPE) { mMatrix.postScale((float)Width / mActualRect.width(), (float)Height / mActualRect.height()); } else { mMatrix.postScale((float)Height / mActualRect.width(), (float)Width / mActualRect.height()); } mMatrix.postTranslate((float)Width / 2, (float)Height / 2); foreach (Face face in mFaces) { mBoundRect.set(face.Bounds); mMatrix.mapRect(mBoundRect); mPaint.Color = Color.BLUE; mPaint.StrokeWidth = 3; canvas.drawRect(mBoundRect, mPaint); { // Additional features may not supported. float[] point = new float[2]; mPaint.Color = Color.RED; mPaint.StrokeWidth = 10; if (face.LeftEyePosition != null) { mMatrix.mapPoints(point, new float[] { face.LeftEyePosition.x, face.LeftEyePosition.y }); canvas.drawPoint(point[0], point[1], mPaint); } if (face.RightEyePosition != null) { mMatrix.mapPoints(point, new float[] { face.RightEyePosition.x, face.RightEyePosition.y }); canvas.drawPoint(point[0], point[1], mPaint); } if (face.MouthPosition != null) { mMatrix.mapPoints(point, new float[] { face.MouthPosition.x, face.MouthPosition.y }); canvas.drawPoint(point[0], point[1], mPaint); } mPaint.Color = Color.YELLOW; mPaint.StrokeWidth = 3; mPaint.TextSize = 30; if (face.Id != Face.ID_UNSUPPORTED) { canvas.drawText(string.Format("ID:{0:D}, Score:{1:D}", face.Id, face.Score), mBoundRect.left, mBoundRect.top, mPaint); } else { canvas.drawText(string.Format("Score:{0:D}", face.Score), mBoundRect.left, mBoundRect.top, mPaint); } } } } }
protected internal override void onDraw(Canvas canvas) { if (mFaces != null && mZoomRect != null) { // Prepare matrix mMatrix.reset(); mAspectRatio.reset(); mActualRect.set(0, 0, mPreviewSize.Width, mPreviewSize.Height); // First apply zoom (crop) rect. // Unlike the documentation, many device does not report final crop region. // So, here we calculate final crop region which takes account aspect ratio between crop region and preview size. { mRevisionZoomRect.set(mZoomRect); float left = mRevisionZoomRect.left; float top = mRevisionZoomRect.top; mRevisionZoomRect.offsetTo(0, 0); mAspectRatio.setRectToRect(mActualRect, mRevisionZoomRect, Matrix.ScaleToFit.CENTER); mAspectRatio.mapRect(mActualRect); mActualRect.offset(left, top); } mMatrix.postTranslate(-mActualRect.centerX(), -mActualRect.centerY()); // compensate mirror mMatrix.postScale(mFacing == SCameraCharacteristics.LENS_FACING_FRONT ? - 1 : 1, 1); // Then rotate and scale to UI size mMatrix.postRotate(mRotation); if (mOrientation == Configuration.ORIENTATION_LANDSCAPE) { mMatrix.postScale((float) Width / mActualRect.width(), (float) Height / mActualRect.height()); } else { mMatrix.postScale((float) Height / mActualRect.width(), (float) Width / mActualRect.height()); } mMatrix.postTranslate((float)Width / 2, (float)Height / 2); foreach (Face face in mFaces) { mBoundRect.set(face.Bounds); mMatrix.mapRect(mBoundRect); mPaint.Color = Color.BLUE; mPaint.StrokeWidth = 3; canvas.drawRect(mBoundRect, mPaint); { // Additional features may not supported. float[] point = new float[2]; mPaint.Color = Color.RED; mPaint.StrokeWidth = 10; if (face.LeftEyePosition != null) { mMatrix.mapPoints(point, new float[]{face.LeftEyePosition.x, face.LeftEyePosition.y}); canvas.drawPoint(point[0], point[1], mPaint); } if (face.RightEyePosition != null) { mMatrix.mapPoints(point, new float[]{face.RightEyePosition.x, face.RightEyePosition.y}); canvas.drawPoint(point[0], point[1], mPaint); } if (face.MouthPosition != null) { mMatrix.mapPoints(point, new float[]{face.MouthPosition.x, face.MouthPosition.y}); canvas.drawPoint(point[0], point[1], mPaint); } mPaint.Color = Color.YELLOW; mPaint.StrokeWidth = 3; mPaint.TextSize = 30; if (face.Id != Face.ID_UNSUPPORTED) { canvas.drawText(string.Format("ID:{0:D}, Score:{1:D}", face.Id, face.Score), mBoundRect.left, mBoundRect.top, mPaint); } else { canvas.drawText(string.Format("Score:{0:D}", face.Score), mBoundRect.left, mBoundRect.top, mPaint); } } } } }
public override void draw(android.graphics.Canvas canvas, android.graphics.Paint paint) { canvas.drawRect(mRect, paint); }