public static Matrix parseTransformRotate(String pString) { var start = SVGConstants.ATTRIBUTE_TRANSFORM_VALUE_ROTATE.Length + 1; var svgNumberParserFloatResult = pString.Substring(start, pString.IndexOf(')') - start).ParseFloats (); SVGTransformParser.assertNumberParserResultNumberCountMinimum(svgNumberParserFloatResult, 1); float angle = svgNumberParserFloatResult[0]; float cx = 0; float cy = 0; if (svgNumberParserFloatResult.Length > 2) { cx = svgNumberParserFloatResult[1]; cy = svgNumberParserFloatResult[2]; } Matrix matrix = new Matrix(); matrix.PostTranslate(cx, cy); matrix.PostRotate(angle); matrix.PostTranslate(-cx, -cy); return matrix; }
public Matrix GetRotateMatrix() { // By default this is an identity matrix. Matrix matrix = new Matrix(); if (Rotation != 0) { // We want to do the rotation at origin, but since the bounding // rectangle will be changed after rotation, so the delta values // are based on old & new width/height respectively. int cx = Bitmap.Width / 2; int cy = Bitmap.Height / 2; matrix.PreTranslate(-cx, -cy); matrix.PostRotate(Rotation); matrix.PostTranslate(Width / 2, Height / 2); } return matrix; }
AMatrix CreateMatrix() { AMatrix matrix = new AMatrix(); RectF drawableBounds = new RectF(_drawable.Bounds); float halfStrokeWidth = _drawable.Paint.StrokeWidth / 2; drawableBounds.Left += halfStrokeWidth; drawableBounds.Top += halfStrokeWidth; drawableBounds.Right -= halfStrokeWidth; drawableBounds.Bottom -= halfStrokeWidth; switch (_aspect) { case Stretch.None: break; case Stretch.Fill: matrix.SetRectToRect(_pathFillBounds, drawableBounds, AMatrix.ScaleToFit.Fill); break; case Stretch.Uniform: matrix.SetRectToRect(_pathFillBounds, drawableBounds, AMatrix.ScaleToFit.Center); break; case Stretch.UniformToFill: float widthScale = drawableBounds.Width() / _pathFillBounds.Width(); float heightScale = drawableBounds.Height() / _pathFillBounds.Height(); float maxScale = Math.Max(widthScale, heightScale); matrix.SetScale(maxScale, maxScale); matrix.PostTranslate( drawableBounds.Left - maxScale * _pathFillBounds.Left, drawableBounds.Top - maxScale * _pathFillBounds.Top); break; } return(matrix); }
droidGraphics.Matrix ComputeStretchMatrix() { droidGraphics.Matrix matrix = new droidGraphics.Matrix(); // Get the drawable bounds decreased by stroke thickness droidGraphics.RectF drawableBounds = new droidGraphics.RectF(drawable.Bounds); float halfStrokeWidth = drawable.Paint.StrokeWidth / 2; drawableBounds.Left += halfStrokeWidth; drawableBounds.Top += halfStrokeWidth; drawableBounds.Right -= halfStrokeWidth; drawableBounds.Bottom -= halfStrokeWidth; switch (stretch) { case Stretch.None: break; case Stretch.Fill: matrix.SetRectToRect(pathFillBounds, drawableBounds, droidGraphics.Matrix.ScaleToFit.Fill); break; case Stretch.Uniform: matrix.SetRectToRect(pathFillBounds, drawableBounds, droidGraphics.Matrix.ScaleToFit.Center); break; case Stretch.UniformToFill: float widthScale = drawableBounds.Width() / pathFillBounds.Width(); float heightScale = drawableBounds.Height() / pathFillBounds.Height(); float maxScale = Math.Max(widthScale, heightScale); matrix.SetScale(maxScale, maxScale); matrix.PostTranslate(drawableBounds.Left - maxScale * pathFillBounds.Left, drawableBounds.Top - maxScale * pathFillBounds.Top); break; } return(matrix); }
// * // * Sets the TextureView transform to preserve the aspect ratio of the video. // private void AdjustAspectRatio(int videoWidth, int videoHeight) { int viewWidth = mTextureView.Width; int viewHeight = mTextureView.Height; double aspectRatio = (double) videoHeight / videoWidth; int newWidth, newHeight; if (viewHeight > (int)(viewWidth * aspectRatio)) { // limited by narrow width; restrict height newWidth = viewWidth; newHeight = (int)(viewWidth * aspectRatio); } else { // limited by short height; restrict width newWidth = (int)(viewHeight / aspectRatio); newHeight = viewHeight; } int xoff = (viewWidth - newWidth) / 2; int yoff = (viewHeight - newHeight) / 2; Log.Verbose(TAG, "video=" + videoWidth + "x" + videoHeight + " view=" + viewWidth + "x" + viewHeight + " newView=" + newWidth + "x" + newHeight + " off=" + xoff + "," + yoff); Matrix txform = new Matrix(); mTextureView.GetTransform(txform); txform.SetScale((float) newWidth / viewWidth, (float) newHeight / viewHeight); //txform.postRotate(10); // just for fun txform.PostTranslate(xoff, yoff); mTextureView.SetTransform(txform); }
protected override void OnDraw(Canvas canvas) { coreX = Width / 2; coreY = Height / 2; roundRadius = (int)(Width / 2 * radiusDistance); //计算中心圆圈半径 RectF rect = new RectF(0, 0, Width, Height); if (roundMenus != null && roundMenus.Count > 0) { float sweepAngle = 360 / roundMenus.Count; //每个弧形的角度 deviationDegree = sweepAngle / 2; //其实的偏移角度,如果4个扇形的时候是X形状,而非+,设为0试试就知道什么意思了 for (int i = 0; i < roundMenus.Count; i++) { RoundMenu roundMenu = roundMenus[i]; //填充 Paint paint = new Paint(); paint.AntiAlias = true; if (onClickState == i) { //选中 paint.Color = new Color(roundMenu.selectSolidColor); } else { //未选中 paint.Color = new Color(roundMenu.solidColor); } canvas.DrawArc(rect, deviationDegree + (i * sweepAngle), sweepAngle, true, paint); //画描边 paint = new Paint(); paint.AntiAlias = true; paint.StrokeWidth = roundMenu.strokeSize; paint.SetStyle(Paint.Style.Stroke); paint.Color = new Color(roundMenu.strokeColor); canvas.DrawArc(rect, deviationDegree + (i * sweepAngle), sweepAngle, roundMenu.useCenter, paint); //画图案 Matrix matrix = new Matrix(); matrix.PostTranslate((float)((coreX + Width / 2 * roundMenu.iconDistance) - (roundMenu.icon.Width / 2)), coreY - (roundMenu.icon.Height / 2)); matrix.PostRotate(((i + 1) * sweepAngle), coreX, coreY); canvas.DrawBitmap(roundMenu.icon, matrix, null); } } //画中心圆圈 if (isCoreMenu) { //填充 RectF rect1 = new RectF(coreX - roundRadius, coreY - roundRadius, coreX + roundRadius, coreY + roundRadius); Paint paint = new Paint(); paint.AntiAlias = true; paint.StrokeWidth = coreMenuStrokeSize; if (onClickState == -1) { paint.Color = new Color(coreMenuSelectColor); } else { paint.Color = new Color(coreMenuColor); } canvas.DrawArc(rect1, 0, 360, true, paint); //画描边 paint = new Paint(); paint.AntiAlias = true; paint.StrokeWidth = coreMenuStrokeSize; paint.SetStyle(Paint.Style.Stroke); paint.Color = new Color(coreMenuStrokeColor); canvas.DrawArc(rect1, 0, 360, true, paint); if (coreBitmap != null) { //画中心圆圈的"OK"图标 canvas.DrawBitmap(coreBitmap, coreX - coreBitmap.Width / 2, coreY - coreBitmap.Height / 2, null); //在 0,0坐标开始画入src } } }
//@Override protected override void onLoadingDrawableSet(Drawable imageDrawable) { if (null != imageDrawable) { int dHeight = imageDrawable.IntrinsicHeight; int dWidth = imageDrawable.IntrinsicWidth; /** * We need to set the width/height of the ImageView so that it is * square with each side the size of the largest drawable dimension. * This is so that it doesn't clip when rotated. */ ViewGroup.LayoutParams lp = mHeaderImage.LayoutParameters; lp.Width = lp.Height = Math.Max(dHeight, dWidth); mHeaderImage.RequestLayout(); /** * We now rotate the Drawable so that is at the correct rotation, * and is centered. */ mHeaderImage.SetScaleType(ImageView.ScaleType.Matrix); Matrix matrix = new Matrix(); matrix.PostTranslate((lp.Width - dWidth) / 2f, (lp.Height - dHeight) / 2f); matrix.PostRotate(getDrawableRotationAngle(), lp.Width / 2f, lp.Height / 2f); mHeaderImage.ImageMatrix = matrix; } }
/// <summary> /// Setup the base matrix so that the image is centered and scaled properly. /// </summary> private void getProperBaseMatrix(RotateBitmap bitmap, Matrix matrix) { float viewWidth = _width; //Width; float viewHeight = _height; //Height; float w = bitmap.Width; float h = bitmap.Height; int rotation = bitmap.Rotation; matrix.Reset(); // We limit up-scaling to 2x otherwise the result may look bad if it's // a small icon. float widthScale = viewWidth / w; //Math.Min(viewWidth / w, 2.0f); float heightScale = viewHeight / h; //Math.Min(viewHeight / h, 2.0f); float scale = Math.Min(widthScale, heightScale); matrix.PostConcat(bitmap.GetRotateMatrix()); matrix.PostScale(scale, scale); matrix.PostTranslate( (viewWidth - w * scale) / 2F, (viewHeight - h * scale) / 2F); }
private static Matrix parseTransformTranslate(String pString) { var start = SVGConstants.ATTRIBUTE_TRANSFORM_VALUE_TRANSLATE.Length + 1; var svgNumberParserFloatResult = pString.Substring(start, pString.IndexOf(')') - start).ParseFloats (); SVGTransformParser.assertNumberParserResultNumberCountMinimum(svgNumberParserFloatResult, 1); float tx = svgNumberParserFloatResult[0]; float ty = 0; if (svgNumberParserFloatResult.Length > 1) { ty = svgNumberParserFloatResult[1]; } Matrix matrix = new Matrix(); matrix.PostTranslate(tx, ty); return matrix; }
protected virtual void OnCreate(Bundle bundle, RedLaserSettings settings) { base.OnCreate (bundle); this.settings = settings; StatusManager.Initialize(this); Log.Debug(TAG, "Starting capture activity"); var window = Window; window.AddFlags(WindowManagerFlags.KeepScreenOn); this.mBarcodeScanLayout = new BarcodeScanLayout(this, this.settings.HoldStill, this.settings.AlignBarcode); SetContentView(this.mBarcodeScanLayout); var metrics = new DisplayMetrics(); WindowManager.DefaultDisplay.GetMetrics(metrics); this.mWidth = metrics.WidthPixels; this.mHeight = metrics.HeightPixels; this.mDensity = metrics.Density; var logo = new ImageView(this); logo.SetScaleType(ImageView.ScaleType.Matrix); logo.SetImageResource(LogoResource); var matrix = new Matrix(); matrix.PostRotate(270.0f); if(mWidth < mHeight) { var temp = mWidth; mWidth = mHeight; mHeight = temp; } var offset = 0; if(mDensity == 1.0f) { offset = 100; } matrix.PostTranslate((float)(mWidth / 2.0d + mWidth / 8 * mDensity) + offset, (float)(mHeight / 2.80 + 160.0f * mDensity)); logo.ImageMatrix = matrix; CameraManager.Init(Application); viewfinderView = mBarcodeScanLayout.ViewFinderView; handler = null; hasSurface = false; }