本文整理汇总了C#中Xwt.Drawing.Context.DrawImage方法的典型用法代码示例。如果您正苦于以下问题:C# Context.DrawImage方法的具体用法?C# Context.DrawImage怎么用?C# Context.DrawImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Xwt.Drawing.Context
的用法示例。
在下文中一共展示了Context.DrawImage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnDraw
protected override void OnDraw (Context ctx, Rectangle dirtyRect)
{
Image image = new CustomImage ();
int x = 0;
for (int n=4; n < 50; n += 4) {
ctx.DrawImage (image.WithSize (n, n), x, 0);
x += n;
}
int maxSize = 48;
var warn = StockIcons.Error;
x = 0;
for (int n=8; n <= maxSize; n += 2) {
ctx.DrawImage (warn, x, 50, n, n);
x += n;
}
warn = StockIcons.Error.WithSize (maxSize).ToBitmap ();
x = 0;
for (int n=8; n <= maxSize; n += 2) {
ctx.DrawImage (warn, x, 100, n, n);
x += n;
}
ctx.DrawImage (image.WithSize (1000), new Rectangle (400, 0, 200, 1000), new Rectangle (0, 200, 200, 200));
ctx.DrawImage (image.WithSize (1000), new Rectangle (400, 0, 200, 50), new Rectangle (210, 200, 200, 200));
}
示例2: OnDraw
protected override void OnDraw (Context ctx, Rectangle dirtyRect)
{
var w = Math.Truncate (Bounds.Width / 2);
var h = Math.Truncate (Bounds.Height / 2);
ctx.DrawImage (img_ss, new Rectangle (0, 0, w, h).Inflate (-10, -10));
ctx.DrawImage (img_tt, new Rectangle (w, 0, w, h).Inflate (-10, -10));
ctx.DrawImage (img_st, new Rectangle (0, h, w, h).Inflate (-10, -10));
ctx.DrawImage (img_ts, new Rectangle (w, h, w, h).Inflate (-10, -10));
}
示例3: PatternsAndImages
public void PatternsAndImages (Context ctx, double x, double y)
{
ctx.Save ();
ctx.Translate (x, y);
ctx.SetColor (Colors.Black);
// Dashed lines
ctx.SetLineWidth (2);
ctx.SetLineDash (15, 10, 10, 5, 5);
ctx.Rectangle (10, 10, 100, 100);
ctx.Stroke ();
ctx.SetLineDash (0);
// Image
var arcColor = new Color (1, 0, 1);
ImageBuilder ib = new ImageBuilder (30, 30);
ib.Context.Arc (15, 15, 15, 0, 360);
ib.Context.SetColor (arcColor);
ib.Context.Fill ();
ib.Context.SetColor (Colors.DarkKhaki);
ib.Context.Rectangle (0, 0, 5, 5);
ib.Context.Fill ();
var img = ib.ToVectorImage ();
ctx.DrawImage (img, 0, 0);
ctx.DrawImage (img, 0, 50, 50, 10);
ctx.Arc (100, 100, 15, 0, 360);
arcColor.Alpha = 0.4;
ctx.SetColor (arcColor);
ctx.Fill ();
// ImagePattern
ctx.Save ();
ctx.Translate (x + 130, y);
ctx.Pattern = new ImagePattern (img);
ctx.Rectangle (0, 0, 100, 100);
ctx.Fill ();
ctx.Restore ();
ctx.Restore ();
// Setting pixels
ctx.SetLineWidth (1);
for (int i=0; i<50;i++) {
for (var j=0; j<50;j++) {
Color c = Color.FromHsl (0.5, (double)i / 50d, (double)j / 50d);
ctx.Rectangle (i, j, 1, 1);
ctx.SetColor (c);
ctx.Fill ();
}
}
}
示例4: OnDraw
protected override void OnDraw(Context ctx, Rectangle dirtyRect)
{
// Line arround
ctx.SetColor(Colors.DarkGray);
// Drive line arround
ctx.Rectangle(Bounds);
ctx.Fill();
ctx.SetColor(Colors.Gray);
ctx.Rectangle(Bounds.Inflate(-margin, -margin));
ctx.Fill();
// Draw image
ctx.DrawImage(Image.FromResource(Logo), 5.0, 5.0);
// Draw text
ctx.SetColor(Colors.White);
TextLayout _layout = new TextLayout();
_layout.Font = Font.WithSize(22);
_layout.Text = Label;
_layout.SetFontWeight(FontWeight.Bold, 0, Label.Length);
// Cocoa layouts
ctx.DrawTextLayout(_layout, 45, ((Config.Cocoa || Config.Gtk) ? 5 : 2));
}
示例5: OnDraw
protected override void OnDraw (Context ctx, Rectangle dirtyRect)
{
base.OnDraw (ctx, dirtyRect);
for (int y = 0; y < img.Size.Height / 50; ++y) {
for (int x = 0; x < img.Size.Width / 50; ++x) {
ctx.DrawImage (img, new Rectangle (x*50, y*50, 50, 50), new Rectangle (x*55, y*55, 50, 50));
}
}
}
示例6: OnDraw
protected override void OnDraw(Context ctx, Rectangle dirtyRect)
{
base.OnDraw(ctx, dirtyRect);
if (Image != null) {
double width = Bounds.Width == 1 ? Image.Width : Bounds.Width;
if (Bounds.Width == 1)
WidthRequest = width;
// Scale height respect width
double height = (Bounds.Width / Image.Width) * Image.Height;
if (HeightRequest != height)
HeightRequest = height;
else
height = Bounds.Height;
ctx.DrawImage(Image, 0, 0, width, height);
}
}
示例7: OnDraw
protected override void OnDraw (Context ctx, Rectangle dirtyRect)
{
base.OnDraw (ctx, dirtyRect);
ctx.Save ();
if (parent.CurrentRow < 0)
return;
var row_bounds = parent.ListView.GetRowBounds (parent.CurrentRow, false);
var row_bg_bounds = parent.ListView.GetRowBounds (parent.CurrentRow, true);
if (TrackerBg != null) {
ctx.DrawImage (TrackerBg, row_bg_bounds, new Rectangle (0, 0, row_bg_bounds.Width, row_bg_bounds.Height));
}
foreach (var col in parent.ListView.Columns) {
foreach (var cell in col.Views) {
var cell_bg_bounds = parent.ListView.GetCellBounds (parent.CurrentRow, cell, true);
var cell_bounds = parent.ListView.GetCellBounds (parent.CurrentRow, cell, false);
cell_bounds.Y -= row_bg_bounds.Y;
cell_bounds.X += parent.ListView.HorizontalScrollControl.Value;
cell_bg_bounds.Y -= row_bg_bounds.Y;
cell_bg_bounds.X += parent.ListView.HorizontalScrollControl.Value;
ctx.SetColor (Colors.Red);
ctx.Rectangle (cell_bg_bounds);
ctx.Stroke ();
ctx.SetColor (Colors.Green);
ctx.Rectangle (cell_bounds);
ctx.Stroke ();
}
}
row_bounds.Y -= row_bg_bounds.Y;
row_bounds.X += parent.ListView.HorizontalScrollControl.Value;
row_bg_bounds.Y = 0;
row_bg_bounds.X += parent.ListView.HorizontalScrollControl.Value;
ctx.SetColor (Colors.Red);
ctx.Rectangle (row_bg_bounds);
ctx.Stroke ();
ctx.SetColor (Colors.Blue);
ctx.Rectangle (row_bounds);
ctx.Stroke ();
ctx.Restore ();
}
示例8: OnDraw
protected override void OnDraw(Context ctx, Rectangle dirtyRect)
{
if (colorBox == null) {
using (var ib = new ImageBuilder (size, size)) {
for (int i=0; i<size; i++) {
for (int j=0; j<size; j++) {
ib.Context.Rectangle (i, j, 1, 1);
ib.Context.SetColor (GetColor (i,j));
ib.Context.Fill ();
}
}
colorBox = ib.ToImage ();
}
}
ctx.DrawImage (colorBox, padding, padding);
ctx.SetLineWidth (1);
ctx.SetColor (Colors.Black);
ctx.Rectangle (selection.X + padding - 2 + 0.5, selection.Y + padding - 2 + 0.5, 4, 4);
ctx.Stroke ();
}
示例9: OnDraw
protected override void OnDraw(Context ctx, Rectangle dirtyRect)
{
base.OnDraw(ctx, dirtyRect);
if (isPressed || Active) {
ctx.DrawImage(toggleButton && isPressed ? bg[1].WithAlpha(0.8) : bg[1], Point.Zero);
} else {
ctx.DrawImage(bg[0], Point.Zero);
}
ctx.DrawImage(icon, new Point(((icon.Width + bg[0].Width) / 2) - icon.Width, 0));
}
示例10: OnDraw
protected override void OnDraw(Context ctx, Rectangle dirtyRect)
{
base.OnDraw(ctx, dirtyRect);
if (image != null) {
if (Heighlighted && IsThumbnail) {
ctx.RoundRectangle(new Rectangle(Point.Zero, image.Size), 3);
ctx.SetColor(Colors.LightSteelBlue);
ctx.Fill();
}
ctx.DrawImage(image, (new Rectangle(Point.Zero, image.Size)).Inflate(-3, -3));
if (mask != null && ShowMask) {
ctx.DrawImage(MaskBitmap, (new Rectangle(Point.Zero, image.Size)).Inflate(-3, -3), 0.6);
}
}
if (isEditMode) {
Point scaleFactor = new Point(
scan.Size.Width / image.Size.Width,
scan.Size.Height / image.Size.Height);
ctx.SetColor(Mask.maskColor);
foreach (MaskEntry p in scan.Mask.MaskPositions) {
switch (p.type) {
case MaskEntryType.Point:
ctx.SetLineWidth(p.pointerSize / scaleFactor.Y * 2);
ctx.LineTo(p.position.X / scaleFactor.X, p.position.Y / scaleFactor.Y);
ctx.Stroke();
ctx.Arc(
p.position.X / scaleFactor.X, p.position.Y / scaleFactor.Y,
p.pointerSize / scaleFactor.Y, 0, 360);
ctx.Fill();
ctx.MoveTo(p.position.X / scaleFactor.X, p.position.Y / scaleFactor.Y);
break;
case MaskEntryType.Space:
ctx.Stroke();
ctx.ClosePath();
break;
case MaskEntryType.Delete:
ctx.Arc(
p.position.X / scaleFactor.X, p.position.Y / scaleFactor.Y,
p.pointerSize / scaleFactor.Y, 0, 360);
ctx.Save();
ctx.Clip();
int newX = (int) Math.Min(Math.Max(
p.position.X / scaleFactor.X - pointerSize / scaleFactor.Y, 0), scan.Size.Width);
int newY = (int) Math.Min(Math.Max(
p.position.Y / scaleFactor.Y - pointerSize / scaleFactor.Y, 0), scan.Size.Height);
using (ImageBuilder ib =
new ImageBuilder((pointerSize / scaleFactor.Y * 2), (pointerSize / scaleFactor.Y * 2))) {
BitmapImage bi = ib.ToBitmap();
image.WithBoxSize(image.Size).ToBitmap().CopyArea(
newX, newY,
(int) (pointerSize / scaleFactor.Y * 2), (int) (pointerSize / scaleFactor.Y * 2),
bi, 0, 0);
ctx.DrawImage(bi, new Point(newX, newY));
}
ctx.Restore();
ctx.ClosePath();
break;
}
}
ctx.Stroke();
if (mousePosition != Point.Zero) {
ctx.Arc(mousePosition.X, mousePosition.Y, pointerSize / Math.Max(scaleFactor.X, scaleFactor.Y), 0, 360);
ctx.Fill();
if (mousePositionStart != Point.Zero) {
ctx.SetLineWidth((pointerSize / Math.Max(scaleFactor.X, scaleFactor.Y)) * 2);
ctx.SetColor(Mask.maskColor);
ctx.Arc(mousePositionStart.X, mousePositionStart.Y, pointerSize / Math.Max(scaleFactor.X, scaleFactor.Y), 0, 360);
ctx.Fill();
ctx.MoveTo(mousePosition);
ctx.LineTo(mousePositionStart);
ctx.Stroke();
}
}
}
}
示例11: Draw
//.........这里部分代码省略.........
((AxesConstraint)axesConstraints[i]).ApplyConstraint(
pXAxis1, pYAxis1, pXAxis2, pYAxis2 );
}
// draw legend if have one.
// Note: this will update axes if necessary.
Point legendPosition = new Point(0,0);
if (legend != null) {
legend.UpdateAxesPositions (
pXAxis1, pYAxis1, pXAxis2, pYAxis2,
drawables, scale, padding, bounds,
out legendPosition );
}
double newXAxis2Height = pXAxis2.PhysicalMin.Y;
double titleExtraOffset = oldXAxis2Height - newXAxis2Height;
// now we are ready to define the bounding box for the plot area (to use in clipping
// operations.
plotAreaBoundingBoxCache = new Rectangle (
Math.Min (pXAxis1.PhysicalMin.X, pXAxis1.PhysicalMax.X),
Math.Min (pYAxis1.PhysicalMax.Y, pYAxis1.PhysicalMin.Y),
Math.Abs (pXAxis1.PhysicalMax.X - pXAxis1.PhysicalMin.X + 1),
Math.Abs (pYAxis1.PhysicalMin.Y - pYAxis1.PhysicalMax.Y + 1)
);
bbXAxis1Cache = pXAxis1.GetBoundingBox ();
bbXAxis2Cache = pXAxis2.GetBoundingBox ();
bbYAxis1Cache = pYAxis1.GetBoundingBox ();
bbYAxis2Cache = pYAxis2.GetBoundingBox ();
// Fill in the background.
if (plotBackImage != null) {
Rectangle imageRect = (Rectangle)plotAreaBoundingBoxCache;
ctx.DrawImage (Utils.TiledImage (plotBackImage , imageRect.Size), imageRect);
}
//else if (plotBackBrush_ != null) {
// g.FillRectangle(
// plotBackBrush_.Get( (Rectangle)plotAreaBoundingBoxCache ),
// (Rectangle)plotAreaBoundingBoxCache );
//}
else {
ctx.SetColor (plotBackColor);
ctx.Rectangle ((Rectangle)plotAreaBoundingBoxCache);
ctx.Fill ();
}
// draw title at centre of Physical X-axis and at top of plot
titleOrigin.X = (pXAxis2.PhysicalMax.X + pXAxis2.PhysicalMin.X)/2.0;
titleOrigin.Y = bounds.Top + padding - titleExtraOffset;
Size s = DrawTitle (ctx, titleOrigin, scale);
bbTitleCache = new Rectangle (titleOrigin.X-s.Width/2, titleOrigin.Y, s.Width, s.Height);
// draw drawables..
bool legendDrawn = false;
for (int i_o = 0; i_o < ordering.Count; ++i_o) {
int i = (int)ordering.GetByIndex (i_o);
double zOrder = (double)ordering.GetKey (i_o);
if (zOrder > legendZOrder) {
// draw legend.
if (!legendDrawn && legend != null) {
legend.Draw (ctx, legendPosition, drawables, scale);
legendDrawn = true;
示例12: Draw
//.........这里部分代码省略.........
out legendPosition );
}
double newXAxis2Height = pXAxis2.PhysicalMin.Y;
double titleExtraOffset = oldXAxis2Height - newXAxis2Height;
// now we are ready to define the clipping region
plotAreaBoundingBoxCache = new Rectangle (
Math.Min (pXAxis1.PhysicalMin.X, pXAxis1.PhysicalMax.X),
Math.Min (pYAxis1.PhysicalMax.Y, pYAxis1.PhysicalMin.Y),
Math.Abs (pXAxis1.PhysicalMax.X - pXAxis1.PhysicalMin.X + 1),
Math.Abs (pYAxis1.PhysicalMin.Y - pYAxis1.PhysicalMax.Y + 1)
);
bbXAxis1Cache = pXAxis1.GetBoundingBox ();
bbXAxis2Cache = pXAxis2.GetBoundingBox ();
bbYAxis1Cache = pYAxis1.GetBoundingBox ();
bbYAxis2Cache = pYAxis2.GetBoundingBox ();
Rectangle plotBounds = (Rectangle)plotAreaBoundingBoxCache;
// set the clipping region.. (necessary for zoom)
// Note: although clipping is enforced by the clip region, it is probably more efficient
// for each Drawable to check against the plotBounds and not draw if points are outside.
// This hasn't yet been implemented
ctx.Save ();
ctx.Rectangle (plotBounds);
ctx.Clip ();
// Fill in the plot background.
if (plotBackImage != null) {
// Ensure plotBounds has integer size for correct tiling/drawing
plotBounds.Width = Math.Truncate (plotBounds.Width);
plotBounds.Height = Math.Truncate (plotBounds.Height);
ctx.DrawImage (Utils.TiledImage (plotBackImage , plotBounds.Size), plotBounds);
}
else if (plotBackGradient != null) {
// Scale plotBackGradient to plotBounds
double startX = plotBounds.X + (plotBackGradient.StartPoint.X * plotBounds.Width);
double startY = plotBounds.Y + (plotBackGradient.StartPoint.Y * plotBounds.Height);
double endX = plotBounds.X + (plotBackGradient.EndPoint.X * plotBounds.Width);
double endY = plotBounds.Y + (plotBackGradient.EndPoint.Y * plotBounds.Height);
LinearGradient g = new LinearGradient (startX, startY, endX, endY);
g.AddColorStop (0, plotBackGradient.StartColor);
g.AddColorStop (1, plotBackGradient.EndColor);
ctx.Rectangle (plotBounds);
ctx.Pattern = g;
ctx.Fill ();
}
else {
ctx.Rectangle (plotBounds);
ctx.SetColor (plotBackColor);
ctx.Fill ();
}
// draw title at centre of Physical X-axis and at top of plot
titleOrigin.X = (pXAxis2.PhysicalMax.X + pXAxis2.PhysicalMin.X)/2.0;
titleOrigin.Y = bounds.Top + Padding - titleExtraOffset;
Size s = DrawTitle (ctx, titleOrigin, scale);
bbTitleCache = new Rectangle (titleOrigin.X-s.Width/2, titleOrigin.Y, s.Width, s.Height);
// draw drawables..
bool legendDrawn = false;
for (int i_o = 0; i_o < ordering.Count; ++i_o) {
示例13: DrawPackageImage
void DrawPackageImage (Context ctx, Rectangle cellArea)
{
Image image = GetValue (ImageField);
if (image == null) {
image = defaultPackageImage;
}
if (PackageImageNeedsResizing (image)) {
Point imageLocation = GetPackageImageLocation (maxPackageImageSize, cellArea);
ctx.DrawImage (
image,
cellArea.Left + packageImagePadding.Left + checkBoxAreaWidth + imageLocation.X,
Math.Round( cellArea.Top + packageImagePadding.Top + imageLocation.Y),
maxPackageImageSize.Width,
maxPackageImageSize.Height);
} else {
Point imageLocation = GetPackageImageLocation (image.Size, cellArea);
ctx.DrawImage (
image,
cellArea.Left + packageImagePadding.Left + checkBoxAreaWidth + imageLocation.X,
Math.Round (cellArea.Top + packageImagePadding.Top + imageLocation.Y));
}
}
示例14: OnDraw
protected override sealed void OnDraw(Context ctx, Rectangle bounds)
{
var frame = GetFrame (ctx.ScaleFactor);
var fixedWidth = frame.Bitmap.Width - 2 - frame.StretchableWidth;
var fixedHeight = frame.Bitmap.Height - 2 - frame.StretchableHeight;
double totalVariableWidth = bounds.Width - fixedWidth / frame.ScaleFactor;
double totalVariableHeight = bounds.Height - fixedHeight / frame.ScaleFactor;
double remainingVariableHeight = totalVariableHeight;
double y = bounds.Y, yb = 1;
int tileIndex = 0;
ctx.Save ();
if (totalVariableWidth < 0) {
if (fixedWidth > 0)
ctx.Scale (bounds.Width / fixedWidth, 1);
totalVariableWidth = 0;
}
if (totalVariableHeight < 0) {
if (fixedHeight > 0)
ctx.Scale (1, bounds.Height / fixedHeight);
totalVariableHeight = 0;
}
foreach (var vs in frame.VerticalSections) {
double sh = CalcSectionSize (frame, vs, totalVariableHeight, frame.StretchableHeight, ref remainingVariableHeight);
double x = bounds.X, xb = 1;
double remainingVariableWidth = totalVariableWidth;
foreach (var hs in frame.HorizontalSections) {
var sourceRegion = new Rectangle (xb, yb, hs.Size, vs.Size);
double sw = CalcSectionSize (frame, hs, totalVariableWidth, frame.StretchableWidth, ref remainingVariableWidth);
var targetRegion = new Rectangle (x, y, sw, sh);
if (vs.Mode != RenderMode.Tile && hs.Mode != RenderMode.Tile) {
var t = GetTile (frame, tileIndex, sourceRegion);
ctx.DrawImage (t, targetRegion);
} else {
double pw = hs.Size / frame.ScaleFactor;
double ph = vs.Size / frame.ScaleFactor;
if (hs.Mode == RenderMode.Stretch) {
pw = targetRegion.Width;
}
if (vs.Mode == RenderMode.Stretch) {
ph = targetRegion.Height;
}
ctx.Save ();
ctx.Translate (targetRegion.Location);
targetRegion.Location = Point.Zero;
ctx.Pattern = new ImagePattern (GetTile (frame, tileIndex, sourceRegion).WithSize (pw, ph));
ctx.NewPath ();
ctx.Rectangle (targetRegion);
ctx.Fill ();
ctx.Restore ();
}
x += sw;
xb += hs.Size;
tileIndex++;
}
yb += vs.Size;
y += sh;
}
ctx.Restore ();
}
示例15: OnDraw
protected override void OnDraw(Context ctx, Rectangle dirtyRect)
{
base.OnDraw(ctx, dirtyRect);
for (int i = 0; i < Size.Width / checkerboard.Width; i++)
{
for (int j = 0; j < Size.Height / checkerboard.Height; j++)
{
ctx.DrawImage(checkerboard, i * checkerboard.Width, j * checkerboard.Height);
}
}
ctx.SetLineWidth(1);
ctx.SetColor(color);
ctx.Rectangle(0, 0, Size.Width - 20, Size.Height);
ctx.Fill();
ctx.SetColor(DefaultColor);
ctx.Rectangle(Size.Width - 20, 0, 20, Size.Height);
ctx.Fill();
ctx.SetColor(Colors.Black);
ctx.Rectangle(0, 0, Size.Width, Size.Height);
ctx.Stroke();
//ctx.SetColor(Color.Brightness > .5 ? Colors.White : Colors.Black);
ctx.SetColor(((-1 * Color.Brightness) + 1) * 1.15 + (Color.Alpha) > 1.2 ? Colors.White : Colors.Black);
ctx.DrawTextLayout(new TextLayout(this) { Text = Color.ToHexString().ToUpper() }, 2, 3);
if (mover && (IsDefaultColor || mx <= Size.Width - 20))
{
ctx.SetColor(new Color(1, 1, 1, .33));
ctx.Rectangle(0, 0, Size.Width - (IsDefaultColor ? 0 : 20), Size.Height);
ctx.Fill();
}
if (!IsDefaultColor)
{
if (mover && mx > Size.Width - 20)
{
ctx.SetColor(new Color(1, 1, 1, .33));
ctx.Rectangle(Size.Width - 20, 0, 20, Size.Height);
ctx.Fill();
}
ctx.SetColor(Colors.Black);
ctx.MoveTo(Size.Width - 19.5, 0);
ctx.RelLineTo(0, Size.Height);
ctx.Stroke();
if (mover)
ctx.DrawImage(resetImage, Size.Width - 18, (Size.Height - 16) / 2, 16, 16);
}
}