本文整理汇总了C#中Android.Graphics.RectF.Height方法的典型用法代码示例。如果您正苦于以下问题:C# RectF.Height方法的具体用法?C# RectF.Height怎么用?C# RectF.Height使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Graphics.RectF
的用法示例。
在下文中一共展示了RectF.Height方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
public override void Draw(Android.Graphics.Canvas canvas)
{
base.Draw(canvas);
var rect = new RectF(0,0,300,300);
switch (TheShape)
{
case Shape.Circle:
canvas.DrawOval(rect, new Paint() { Color = Color.Aqua });
break;
case Shape.Square:
canvas.DrawRect(rect, new Paint() { Color = Color.Red });
break;
case Shape.Triangle:
var path = new Path();
path.MoveTo(rect.CenterX(), 0);
path.LineTo(0, rect.Height());
path.LineTo(rect.Width(), rect.Height());
path.Close();
var paint = new Paint() {Color = Color.Magenta};
paint.SetStyle(Paint.Style.Fill);
canvas.DrawPath(path, paint);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
示例2: Transition
public Transition(RectF srcRect, RectF dstRect, long duration, IInterpolator interpolator) {
if (!MathUtils.HaveSameAspectRatio(srcRect, dstRect)) {
throw new IncompatibleRatioException();
}
_mSrcRect = srcRect;
_mDstRect = dstRect;
_mDuration = duration;
_mInterpolator = interpolator;
// Precomputes a few variables to avoid doing it in onDraw().
_mWidthDiff = dstRect.Width() - srcRect.Width();
_mHeightDiff = dstRect.Height() - srcRect.Height();
_mCenterXDiff = dstRect.CenterX() - srcRect.CenterX();
_mCenterYDiff = dstRect.CenterY() - srcRect.CenterY();
}
示例3: GetImage
Bitmap GetImage (Color strokeColor, Color fillColor, System.Drawing.SizeF size, float scale,
bool shouldCrop = true, bool keepAspectRatio = true)
{
if (size.Width == 0 || size.Height == 0 || scale <= 0)
return null;
float uncroppedScale;
RectF croppedRectangle = new RectF ();
System.Drawing.PointF [] cachedPoints;
if (shouldCrop && (cachedPoints = Points).Any ()) {
croppedRectangle = getCroppedRectangle (cachedPoints);
if (croppedRectangle.Left >= 5)
croppedRectangle.Left -= 5;
if (croppedRectangle.Right <= size.Width - 5)
croppedRectangle.Right += 5;
if (croppedRectangle.Top >= 5)
croppedRectangle.Top -= 5;
if (croppedRectangle.Bottom <= size.Height - 5)
croppedRectangle.Bottom += 5;
float scaleX = (croppedRectangle.Right - croppedRectangle.Left) / Width;
float scaleY = (croppedRectangle.Bottom - croppedRectangle.Top) / Height;
uncroppedScale = 1 / Math.Max (scaleX, scaleY);
} else {
uncroppedScale = scale;
}
Bitmap image;
if (keepAspectRatio)
image = Bitmap.CreateBitmap ((int)size.Width, (int)size.Height,
Bitmap.Config.Argb8888);
else
image = Bitmap.CreateBitmap ((int)(croppedRectangle.Width () * uncroppedScale), (int)(croppedRectangle.Height () * uncroppedScale),
Bitmap.Config.Argb8888);
Canvas canvas = new Canvas (image);
canvas.Scale (uncroppedScale, uncroppedScale);
DrawStrokesOnCanvas (canvas, strokeColor, fillColor, shouldCrop, croppedRectangle);
return image;
}
示例4: growBy
// Grows the cropping rectange by (dx, dy) in image space.
private void growBy(float dx, float dy)
{
if (maintainAspectRatio)
{
if (dx != 0)
{
dy = dx / initialAspectRatio;
}
else if (dy != 0)
{
dx = dy * initialAspectRatio;
}
}
// Don't let the cropping rectangle grow too fast.
// Grow at most half of the difference between the image rectangle and
// the cropping rectangle.
RectF r = new RectF(cropRect);
if (dx > 0F && r.Width() + 2 * dx > imageRect.Width())
{
float adjustment = (imageRect.Width() - r.Width()) / 2F;
dx = adjustment;
if (maintainAspectRatio)
{
dy = dx / initialAspectRatio;
}
}
if (dy > 0F && r.Height() + 2 * dy > imageRect.Height())
{
float adjustment = (imageRect.Height() - r.Height()) / 2F;
dy = adjustment;
if (maintainAspectRatio)
{
dx = dy * initialAspectRatio;
}
}
r.Inset(-dx, -dy);
// Don't let the cropping rectangle shrink too fast.
float widthCap = 25F;
if (r.Width() < widthCap)
{
r.Inset(-(widthCap - r.Width()) / 2F, 0F);
}
float heightCap = maintainAspectRatio
? (widthCap / initialAspectRatio)
: widthCap;
if (r.Height() < heightCap)
{
r.Inset(0F, -(heightCap - r.Height()) / 2F);
}
// Put the cropping rectangle inside the image rectangle.
if (r.Left < imageRect.Left)
{
r.Offset(imageRect.Left - r.Left, 0F);
}
else if (r.Right > imageRect.Right)
{
r.Offset(-(r.Right - imageRect.Right), 0);
}
if (r.Top < imageRect.Top)
{
r.Offset(0F, imageRect.Top - r.Top);
}
else if (r.Bottom > imageRect.Bottom)
{
r.Offset(0F, -(r.Bottom - imageRect.Bottom));
}
cropRect.Set(r);
DrawRect = computeLayout();
context.Invalidate();
}
示例5: Setup
public void Setup(Matrix m, Rect imageRect, RectF cropRect, bool maintainAspectRatio)
{
matrix = new Matrix(m);
this.cropRect = cropRect;
this.imageRect = new RectF(imageRect);
this.maintainAspectRatio = maintainAspectRatio;
initialAspectRatio = cropRect.Width() / cropRect.Height();
DrawRect = computeLayout();
focusPaint.SetARGB(125, 50, 50, 50);
noFocusPaint.SetARGB(125, 50, 50, 50);
outlinePaint.StrokeWidth = 3;
outlinePaint.SetStyle(Paint.Style.Stroke);
outlinePaint.AntiAlias = true;
mode = ModifyMode.None;
init();
}
示例6: GetRectRatio
internal static float GetRectRatio(RectF rect)
{
return rect.Width() / rect.Height();
}
示例7: GenerateRandomRect
/**
* Generates a random rect that can be fully contained within {@code drawableBounds} and
* has the same aspect ratio of {@code viewportRect}. The dimensions of this random rect
* won't be higher than the largest rect with the same aspect ratio of {@code viewportRect}
* that {@code drawableBounds} can contain. They also won't be lower than the dimensions
* of this upper rect limit weighted by {@code MIN_RECT_FACTOR}.
* @param drawableBounds the bounds of the drawable that will be zoomed and panned.
* @param viewportRect the bounds of the view that the drawable will be shown.
* @return an arbitrary generated rect with the same aspect ratio of {@code viewportRect}
* that will be contained within {@code drawableBounds}.
*/
private RectF GenerateRandomRect(RectF drawableBounds, RectF viewportRect)
{
float drawableRatio = MathUtils.GetRectRatio(drawableBounds);
float viewportRectRatio = MathUtils.GetRectRatio(viewportRect);
RectF maxCrop;
if (drawableRatio > viewportRectRatio)
{
float r = (drawableBounds.Height() / viewportRect.Height()) * viewportRect.Width();
float b = drawableBounds.Height();
maxCrop = new RectF(0, 0, r, b);
}
else
{
float r = drawableBounds.Width();
float b = (drawableBounds.Width() / viewportRect.Width()) * viewportRect.Height();
maxCrop = new RectF(0, 0, r, b);
}
float randomFloat = MathUtils.Truncate((float)_mRandom.NextDouble(), 2);
float factor = MIN_RECT_FACTOR + ((1 - MIN_RECT_FACTOR) * randomFloat);
float width = factor * maxCrop.Width();
float height = factor * maxCrop.Height();
int widthDiff = (int)(drawableBounds.Width() - width);
int heightDiff = (int)(drawableBounds.Height() - height);
int left = widthDiff > 0 ? _mRandom.Next(widthDiff) : 0;
int top = heightDiff > 0 ? _mRandom.Next(heightDiff) : 0;
return new RectF(left, top, left + width, top + height);
}
示例8: Center
/// <summary>
/// Center as much as possible in one or both axis. Centering is
/// defined as follows: if the image is scaled down below the
/// view's dimensions then center it (literally). If the image
/// is scaled larger than the view and is translated out of view
/// then translate it back into view (i.e. eliminate black bars).
/// </summary>
protected void Center(bool horizontal, bool vertical)
{
//return;
if (bitmapDisplayed.Bitmap == null)
{
return;
}
Matrix m = GetImageViewMatrix();
RectF rect = new RectF(0, 0,
bitmapDisplayed.Bitmap.Width,
bitmapDisplayed.Bitmap.Height);
m.MapRect(rect);
float height = rect.Height();
float width = rect.Width();
float deltaX = 0, deltaY = 0;
if (vertical)
{
int viewHeight = Height;
if (height < viewHeight)
{
deltaY = (viewHeight - height) / 2 - rect.Top;
}
else if (rect.Top > 0)
{
deltaY = -rect.Top;
}
else if (rect.Bottom < viewHeight)
{
deltaY = Height - rect.Bottom;
}
}
if (horizontal)
{
int viewWidth = _width; //Width;
if (width < viewWidth)
{
deltaX = (viewWidth - width) / 2 - rect.Left;
}
else if (rect.Left > 0)
{
deltaX = -rect.Left;
}
else if (rect.Right < viewWidth)
{
deltaX = viewWidth - rect.Right;
}
}
PostTranslate(deltaX, deltaY);
ImageMatrix = GetImageViewMatrix();
}
示例9: Draw
public override void Draw (Canvas canvas)
{
base.Draw (canvas);
if (!scaled) {
density = Resources.DisplayMetrics.Density;
padding *= density;
lineWidth *= density;
fontSize *= density;
scaled = true;
}
_highTemps = null;
_lowTemps = null;
_hourlyTemps = null;
if (Forecasts.Count == 0 || Hourly.Count == 0) return;
graphRect = new RectF (padding, padding, canvas.Width - padding, canvas.Height - padding);// CGRect (rect.X + padding, rect.Y + padding, rect.Width - (padding * 2), rect.Height - (padding * 2));
var days = Hourly.GroupBy (h => h.FCTTIME.mday).Select (g => g.First ().FCTTIME.weekday_name_abbrev).ToList ();
var dayCount = hourly ? days.Count : Forecasts.Count;
var xAxisScale = (graphRect.Width () + padding / 2) / dayCount;
inset = xAxisScale / 2;
var highest = (float)(hourly ? HourlyTemps.Max () : HighTemps.Max ());
var lowest = (float)(hourly ? HourlyTemps.Min () : LowTemps.Min ());
scaleHigh = (float)Math.Round (highest, MidpointRounding.AwayFromZero);
scaleLow = lowest < 0 ? (float)Math.Round (lowest, MidpointRounding.AwayFromZero) : (float)Math.Round (lowest);
var rangePadding = Settings.UomTemperature.IsImperial () ? scalePadding : (scalePadding / 2);
scaleHigh += rangePadding;
scaleLow -= rangePadding;
scaleRange = scaleHigh - scaleLow;
var scaleIncrement = scaleRange / dividerCount;
scaleX = (graphRect.Width () - inset) / (hourly ? HourlyTemps.Count : Forecasts.Count);
scaleY = graphRect.Height () / dividerCount;
float x, y;
var white = Color.White;
// Draw x and y axis
var paint = new Paint ();
paint.Color = white;
paint.StrokeWidth = 1;
using (Path path = new Path ()) {
path.MoveTo (graphRect.Left, graphRect.Top);
path.LineTo (graphRect.Left, graphRect.Bottom);
path.LineTo (graphRect.Right, graphRect.Bottom);
paint.SetStyle (Paint.Style.Stroke);
canvas.DrawPath (path, paint);
}
Color translucentBlack = Color.Argb (20, 0, 0, 0);
paint.Color = translucentBlack;
paint.SetStyle (Paint.Style.Fill);
// Draw horizontal gridlines
for (int i = 1; i < dividerCount; i += 2) {
y = graphRect.Bottom - ((i + 1) * scaleY);
using (RectF grid = new RectF (padding, y, graphRect.Right, y + scaleY))
canvas.DrawRect (grid, paint);
}
//.........这里部分代码省略.........
示例10: GetImage
Bitmap GetImage (Color strokeColor, Color fillColor, System.Drawing.SizeF size, float scale,
bool shouldCrop = true)
{
if (size.Width == 0 || size.Height == 0 || scale <= 0)
return null;
float uncroppedScale;
System.Drawing.SizeF uncroppedSize;
RectF croppedRectangle;
if (shouldCrop && Points.Count () != 0) {
croppedRectangle = getCroppedRectangle ();
float scaleX = (croppedRectangle.Right - croppedRectangle.Left) / Width;
float scaleY = (croppedRectangle.Bottom - croppedRectangle.Top) / Height;
uncroppedScale = 1 / Math.Max (scaleX, scaleY);
//uncroppedScale = 1 / getScaleFromSize (croppedRectangle.Size, Bounds);
uncroppedSize = getSizeFromScale (uncroppedScale, size.Width, size.Height);
} else {
uncroppedScale = scale;
uncroppedSize = size;
}
Bitmap image = Bitmap.CreateBitmap ((int)uncroppedSize.Width, (int)uncroppedSize.Height,
Bitmap.Config.Argb8888);
Canvas canvas = new Canvas (image);
canvas.Scale (uncroppedScale, uncroppedScale);
DrawStrokesOnCanvas (canvas, strokeColor, fillColor);
if (shouldCrop && Points.Count () != 0) {
croppedRectangle = getCroppedRectangle ();
RectF scaledRectangle = new RectF (croppedRectangle.Left * uncroppedScale,
croppedRectangle.Top * uncroppedScale,
croppedRectangle.Right * uncroppedScale,
croppedRectangle.Bottom * uncroppedScale);
if (scaledRectangle.Left >= 5)
scaledRectangle.Left -= 5;
if (scaledRectangle.Right <= uncroppedSize.Width - 5)
scaledRectangle.Right += 5;
if (scaledRectangle.Top >= 5)
scaledRectangle.Top -= 5;
if (scaledRectangle.Bottom <= uncroppedSize.Height - 5)
scaledRectangle.Bottom += 5;
image = Bitmap.CreateBitmap (image,
(int) scaledRectangle.Left,
(int) scaledRectangle.Top,
(int) scaledRectangle.Width (),
(int) scaledRectangle.Height ());
}
return image;
}