/// <summary>Draw a bitmap of nine patches.</summary> /// <remarks>Draw a bitmap of nine patches.</remarks> /// <param name="canvas">A container for the current matrix and clip used to draw the bitmap. /// </param> /// <param name="location">Where to draw the bitmap.</param> public virtual void draw(android.graphics.Canvas canvas, android.graphics.Rect location ) { if (!canvas.isHardwareAccelerated()) { nativeDraw(canvas.mNativeCanvas, location, mBitmap.nativeInstance, mChunk, mPaint != null ? mPaint.mNativePaint : null, canvas.mDensity, mBitmap.mDensity); } else { mRect.set(location); canvas.drawPatch(mBitmap, mChunk, mRect, mPaint); } }
public override void initializeInvalidateRegion(int left, int top, int right, int bottom) { android.graphics.RectF region = mPreviousRegion; region.set(left, top, right, bottom); region.inset(-1.0f, -1.0f); if (mFillBefore) { int count = mAnimations.size(); java.util.ArrayList <android.view.animation.Animation> animations = mAnimations; android.view.animation.Transformation temp = mTempTransformation; android.view.animation.Transformation previousTransformation = mPreviousTransformation; { for (int i = count - 1; i >= 0; --i) { android.view.animation.Animation a = animations.get(i); temp.clear(); android.view.animation.Interpolator interpolator = a.mInterpolator; a.applyTransformation(interpolator != null ? interpolator.getInterpolation(0.0f) : 0.0f, temp); previousTransformation.compose(temp); } } } }
protected internal override void onResize(float w, float h) { base.onResize(w, h); android.graphics.RectF r = rect(); mPath.reset(); if (mOuterRadii != null) { mPath.addRoundRect(r, mOuterRadii, android.graphics.Path.Direction.CW); } else { mPath.addRect(r, android.graphics.Path.Direction.CW); } if (mInnerRect != null) { mInnerRect.set(r.left + mInset.left, r.top + mInset.top, r.right - mInset.right, r.bottom - mInset.bottom); if (mInnerRect.width() < w && mInnerRect.height() < h) { if (mInnerRadii != null) { mPath.addRoundRect(mInnerRect, mInnerRadii, android.graphics.Path.Direction.CCW); } else { mPath.addRect(mInnerRect, android.graphics.Path.Direction.CCW); } } } }
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); } } } } }
private void configureBounds() { if (mDrawable == null || !mHaveFrame) { return; } int dwidth = mDrawableWidth; int dheight = mDrawableHeight; int vwidth = getWidth() - mPaddingLeft - mPaddingRight; int vheight = getHeight() - mPaddingTop - mPaddingBottom; bool fits = (dwidth < 0 || vwidth == dwidth) && (dheight < 0 || vheight == dheight ); if (dwidth <= 0 || dheight <= 0 || android.widget.ImageView.ScaleType.FIT_XY == mScaleType) { mDrawable.setBounds(0, 0, vwidth, vheight); mDrawMatrix = null; } else { // We need to do the scaling ourself, so have the drawable // use its native size. mDrawable.setBounds(0, 0, dwidth, dheight); if (android.widget.ImageView.ScaleType.MATRIX == mScaleType) { // Use the specified matrix as-is. if (mMatrix.isIdentity()) { mDrawMatrix = null; } else { mDrawMatrix = mMatrix; } } else { if (fits) { // The bitmap fits exactly, no transform needed. mDrawMatrix = null; } else { if (android.widget.ImageView.ScaleType.CENTER == mScaleType) { // Center bitmap in view, no scaling. mDrawMatrix = mMatrix; mDrawMatrix.setTranslate((int)((vwidth - dwidth) * 0.5f + 0.5f), (int)((vheight - dheight) * 0.5f + 0.5f)); } else { if (android.widget.ImageView.ScaleType.CENTER_CROP == mScaleType) { mDrawMatrix = mMatrix; float scale; float dx = 0; float dy = 0; if (dwidth * vheight > vwidth * dheight) { scale = (float)vheight / (float)dheight; dx = (vwidth - dwidth * scale) * 0.5f; } else { scale = (float)vwidth / (float)dwidth; dy = (vheight - dheight * scale) * 0.5f; } mDrawMatrix.setScale(scale, scale); mDrawMatrix.postTranslate((int)(dx + 0.5f), (int)(dy + 0.5f)); } else { if (android.widget.ImageView.ScaleType.CENTER_INSIDE == mScaleType) { mDrawMatrix = mMatrix; float scale; float dx; float dy; if (dwidth <= vwidth && dheight <= vheight) { scale = 1.0f; } else { scale = System.Math.Min((float)vwidth / (float)dwidth, (float)vheight / (float)dheight ); } dx = (int)((vwidth - dwidth * scale) * 0.5f + 0.5f); dy = (int)((vheight - dheight * scale) * 0.5f + 0.5f); mDrawMatrix.setScale(scale, scale); mDrawMatrix.postTranslate(dx, dy); } else { // Generate the required transform. mTempSrc.set(0, 0, dwidth, dheight); mTempDst.set(0, 0, vwidth, vheight); mDrawMatrix = mMatrix; mDrawMatrix.setRectToRect(mTempSrc, mTempDst, scaleTypeToScaleToFit(mScaleType)); } } } } } } }
protected internal override void onResize(float width, float height) { mRect.set(0, 0, width, height); }