本文整理汇总了C#中System.Windows.Media.Imaging.WriteableBitmap.FillRectangle方法的典型用法代码示例。如果您正苦于以下问题:C# WriteableBitmap.FillRectangle方法的具体用法?C# WriteableBitmap.FillRectangle怎么用?C# WriteableBitmap.FillRectangle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.Imaging.WriteableBitmap
的用法示例。
在下文中一共展示了WriteableBitmap.FillRectangle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PreviewTool
public override WriteableBitmap PreviewTool()
{
var bmp = new WriteableBitmap(_wvm.Brush.Width + 1, _wvm.Brush.Height + 1, 96, 96, PixelFormats.Bgra32, null);
bmp.Clear();
if (_wvm.Brush.Shape == BrushShape.Square)
bmp.FillRectangle(0, 0, _wvm.Brush.Width, _wvm.Brush.Height, Color.FromArgb(127, 0, 90, 255));
else
bmp.FillEllipse(0, 0, _wvm.Brush.Width, _wvm.Brush.Height, Color.FromArgb(127, 0, 90, 255));
_preview = bmp;
return _preview;
}
示例2: AddFrame
private void AddFrame(AnimatedGifEncoder encoder)
{
var rtb = new RenderTargetBitmap((int)this.ActualWidth, (int)this.ActualHeight, 96, 96, PixelFormats.Pbgra32);
rtb.Render(this);
var bitmap = new WriteableBitmap((int)this.ActualWidth, (int)this.ActualHeight, 96, 96, PixelFormats.Pbgra32, null);
bitmap.FillRectangle(0, 0, bitmap.PixelWidth, bitmap.PixelWidth, Colors.Wheat);
bitmap.Lock();
rtb.CopyPixels(
new Int32Rect(0, 0, rtb.PixelWidth, rtb.PixelHeight),
bitmap.BackBuffer,
bitmap.BackBufferStride * bitmap.PixelHeight, bitmap.BackBufferStride);
bitmap.AddDirtyRect(new Int32Rect(0, 0, (int)ActualWidth, (int)ActualHeight));
bitmap.Unlock();
encoder.AddFrame(bitmap);
}
示例3: DrawProperties
private void DrawProperties()
{
_propertiesBitmap = new WriteableBitmap(Screen.PixelWidth, Screen.PixelHeight, 96, 96, PixelFormats.Pbgra32, null);
RenderOptions.SetBitmapScalingMode(_propertiesBitmap, BitmapScalingMode.NearestNeighbor);
var size = Screen.Tileset.TileSize;
for (int y = 0; y < Screen.Height; y++)
{
for (int x = 0; x < Screen.Width; x++)
{
var tile = Screen.TileAt(x, y);
if (tile.Properties.Sinking != 0 || tile.Properties.PushX != 0 || tile.Properties.PushY != 0)
{
_propertiesBitmap.FillRectangle(x * size, y * size, (x + 1) * size, (y + 1) * size, Colors.Purple);
}
else if (tile.Properties.Blocking)
{
_propertiesBitmap.FillRectangle(x * size, y * size, (x + 1) * size, (y + 1) * size, Colors.Green);
}
else if (tile.Properties.Lethal)
{
_propertiesBitmap.FillRectangle(x * size, y * size, (x + 1) * size, (y + 1) * size, Colors.Red);
}
else if (tile.Properties.Climbable)
{
_propertiesBitmap.FillRectangle(x * size, y * size, (x + 1) * size, (y + 1) * size, Colors.Yellow);
}
else if (tile.Properties.GravityMult < 1)
{
_propertiesBitmap.FillRectangle(x * size, y * size, (x + 1) * size, (y + 1) * size, Colors.LightBlue);
}
}
}
}
示例4: Init
public void Init(Syscalls syscalls, Core core, Runtime runtime)
{
PhoneApplicationFrame frame = (PhoneApplicationFrame)Application.Current.RootVisual;
double screenWidth = System.Windows.Application.Current.Host.Content.ActualWidth;
double screenHeight = System.Windows.Application.Current.Host.Content.ActualHeight;
if ((int)screenHeight == 0)
throw new Exception("screenHeight");
PhoneApplicationPage mainPage = (PhoneApplicationPage)frame.Content;
Image mainImage = new Image();
mainPage.Width = screenWidth;
mainPage.Height = screenHeight;
mainImage.Width = screenWidth;
mainImage.Height = screenHeight;
mainPage.Content = mainImage;
// no apparent effect on memory leaks.
runtime.RegisterCleaner(delegate()
{
MoSync.Util.RunActionOnMainThreadSync(() =>
{
mainPage.Content = null;
});
});
mBackBuffer = new WriteableBitmap(
(int)screenWidth,
(int)screenHeight);
mFrontBuffer = new WriteableBitmap(
(int)screenWidth,
(int)screenHeight);
mainImage.Source = mFrontBuffer;
mCurrentDrawTarget = mBackBuffer;
mCurrentWindowsColor = System.Windows.Media.Color.FromArgb(0xff,
(byte)(mCurrentColor >> 16),
(byte)(mCurrentColor >> 8),
(byte)(mCurrentColor));
syscalls.maSetColor = delegate(int rgb)
{
int oldColor = (int)mCurrentColor;
mCurrentColor = 0xff000000 | (uint)(rgb & 0xffffff);
mCurrentWindowsColor = System.Windows.Media.Color.FromArgb(0xff,
(byte)(mCurrentColor >> 16),
(byte)(mCurrentColor >> 8),
(byte)(mCurrentColor));
return oldColor & 0xffffff;
};
syscalls.maSetClipRect = delegate(int x, int y, int w, int h)
{
};
syscalls.maGetClipRect = delegate(int cliprect)
{
};
syscalls.maPlot = delegate(int x, int y)
{
mCurrentDrawTarget.SetPixel(x, y, (int)mCurrentColor);
};
syscalls.maUpdateScreen = delegate()
{
System.Array.Copy(mBackBuffer.Pixels, mFrontBuffer.Pixels, mFrontBuffer.PixelWidth * mFrontBuffer.PixelHeight);
InvalidateWriteableBitmapOnMainThread(mFrontBuffer);
};
syscalls.maFillRect = delegate(int x, int y, int w, int h)
{
mCurrentDrawTarget.FillRectangle(x, y, x + w, y + h, (int)mCurrentColor);
};
syscalls.maLine = delegate(int x1, int y1, int x2, int y2)
{
mCurrentDrawTarget.DrawLine(x1, y1, x2, y2, (int)mCurrentColor);
};
TextBlock textBlock = new TextBlock();
textBlock.FontSize = mCurrentFontSize;
syscalls.maDrawText = delegate(int left, int top, int str)
{
String text = core.GetDataMemory().ReadStringAtAddress(str);
if (text.Length == 0) return;
MoSync.Util.RunActionOnMainThreadSync(() =>
{
textBlock.Text = text;
textBlock.Foreground = new SolidColorBrush(mCurrentWindowsColor);
WriteableBitmap b = new WriteableBitmap(textBlock, null);
mCurrentDrawTarget.Blit(new Rect(left, top, b.PixelWidth, b.PixelHeight),
b,
new Rect(0, 0, b.PixelWidth, b.PixelHeight));
});
};
syscalls.maGetTextSize = delegate(int str)
{
//.........这里部分代码省略.........
示例5: bmpWithSkelFromColor
private WriteableBitmap bmpWithSkelFromColor(WriteableBitmap bmpSource, SkeletonFrame SkelFrame)
{
bmpSource = BitmapFactory.ConvertToPbgra32Format(bmpSource);
Skeletons = new Skeleton[SkelFrame.SkeletonArrayLength];
SkelFrame.CopySkeletonDataTo(Skeletons);
//Go through and draw active skeleton
foreach (Skeleton Skel in Skeletons)
{
if (Skel.TrackingState == SkeletonTrackingState.Tracked)
{
//iterate through each joint in the skeleton
foreach (Joint skeljoint in Skel.Joints)
{
SkeletonPoint JointLocation = Skel.Joints[skeljoint.JointType].Position;
ColorImagePoint Cloc = SkeletonPointToColorImage(JointLocation, ColorImageFormat.RgbResolution640x480Fps30);
bmpSource.FillRectangle((Cloc.X - 5), (Cloc.Y - 5), (Cloc.X + 5), (Cloc.Y + 5), Colors.Purple);
}
foreach (BoneOrientation orientation in Skel.BoneOrientations)
{
}
}
}
return bmpSource;
}
示例6: DrawDarkModule
/// <summary>
/// Draw qrCode dark modules at given position. (It will also include quiet zone area. Set it to zero to exclude quiet zone)
/// </summary>
/// <param name="wBitmap">The w bitmap.</param>
/// <param name="matrix">The matrix.</param>
/// <param name="offsetX">The offset X.</param>
/// <param name="offsetY">The offset Y.</param>
/// <exception cref="ArgumentNullException">Bitmatrix, wBitmap should not equal to null</exception>
///
/// <exception cref="ArgumentOutOfRangeException">wBitmap's pixel width or height should not equal to zero</exception>
/// <remarks></remarks>
public void DrawDarkModule(WriteableBitmap wBitmap, BitMatrix matrix, int offsetX, int offsetY)
{
if (matrix == null)
throw new ArgumentNullException("Bitmatrix");
DrawingSize size = ISize.GetSize(matrix.Width);
if (wBitmap == null)
throw new ArgumentNullException("wBitmap");
else if (wBitmap.PixelHeight == 0 || wBitmap.PixelWidth == 0)
throw new ArgumentOutOfRangeException("wBitmap",
"WriteableBitmap's pixelHeight or PixelWidth are equal to zero");
int padding = (size.CodeWidth - size.ModuleSize*matrix.Width)/2;
int preX = -1;
int moduleSize = size.ModuleSize;
if (moduleSize == 0)
return;
for (int y = 0; y < matrix.Width; y++)
{
for (int x = 0; x < matrix.Width; x++)
{
if (matrix[x, y])
{
if (preX == -1)
preX = x;
if (x == matrix.Width - 1)
{
var moduleArea =
new Int32Rect(preX*moduleSize + padding + offsetX,
y*moduleSize + padding + offsetY,
(x - preX + 1)*moduleSize,
moduleSize);
wBitmap.FillRectangle(moduleArea, DarkColor);
preX = -1;
}
}
else if (preX != -1)
{
var moduleArea =
new Int32Rect(preX*moduleSize + padding + offsetX,
y*moduleSize + padding + offsetY,
(x - preX)*moduleSize,
moduleSize);
wBitmap.FillRectangle(moduleArea, DarkColor);
preX = -1;
}
}
}
}
示例7: VerticalLines
private void VerticalLines()
{
var opacityMask = new WriteableBitmap(width, height);
for (int i = 0; i < width/MaskSizeLevel; i += 2) {
opacityMask.FillRectangle(i * MaskSizeLevel, 0, (i + 1) * MaskSizeLevel, height, Colors.Black);
}
OpacityMask = opacityMask;
}
示例8: DrawQuietZone
/// <summary>
/// Draw quiet zone at offset x,y
/// </summary>
/// <param name="wBitmap">The w bitmap.</param>
/// <param name="pixelWidth">Width of the pixel.</param>
/// <param name="offsetX">The offset X.</param>
/// <param name="offsetY">The offset Y.</param>
/// <remarks></remarks>
private void DrawQuietZone(WriteableBitmap wBitmap, int pixelWidth, int offsetX, int offsetY)
{
wBitmap.FillRectangle(new Int32Rect(offsetX, offsetY, pixelWidth, pixelWidth), LightColor);
}
示例9: CheckerBoard
public void CheckerBoard()
{
var opacityMask = new WriteableBitmap(width, height);
for (int i = 0; i < width/MaskSizeLevel; i += 2) {
for (int j = 0; j < height/MaskSizeLevel; j += 2) {
opacityMask.FillRectangle(i*MaskSizeLevel, j*MaskSizeLevel, (i + 1)*MaskSizeLevel, (j + 1)*MaskSizeLevel,Colors.Black);
}
}
for (int i = 1; i < width/MaskSizeLevel; i += 2) {
for (int j = 1; j < height/MaskSizeLevel; j += 2) {
opacityMask.FillRectangle(i*MaskSizeLevel, j*MaskSizeLevel, (i + 1)*MaskSizeLevel, (j + 1)*MaskSizeLevel,Colors.Black);
}
}
OpacityMask = opacityMask;
}
示例10: HorizontalLines
private void HorizontalLines()
{
var opacityMask = new WriteableBitmap(width, height);
for (int j = 0; j < height/MaskSizeLevel; j += 2) {
opacityMask.FillRectangle(0, j * MaskSizeLevel, width, (j + 1) * MaskSizeLevel, Colors.Black);
}
OpacityMask = opacityMask;
}
示例11: PreviewTool
public override WriteableBitmap PreviewTool()
{
var c = Color.FromArgb(127, 0, 90, 255);
var w = _properties.Width;
var h = _properties.Height;
var bmp = new WriteableBitmap(
w,
w,
96,
96,
System.Windows.Media.PixelFormats.Bgra32,
null);
bmp.Clear();
if (_properties.BrushShape == ToolBrushShape.Square)
bmp.FillRectangle(0, 0, w, h, c);
else bmp.FillEllipse (0, 0, w, h, c);
return bmp;
}
示例12: FillImage
public static void FillImage(WriteableBitmap output, Color color)
{
output.FillRectangle(0, 0, output.Width.Round(), output.Height.Round(), color);
}
示例13: Generate
public WriteableBitmap Generate(String content, Encoding encoding)
{
bool[][] matrix = CalQrcode(encoding.GetBytes(content));
WriteableBitmap image = new WriteableBitmap((matrix.Length * QRCodeScale), (matrix.Length * QRCodeScale));
image.Clear(QRCodeBackgroundColor);
var color = QRCodeForegroundColor;
var a = color.A + 1;
var col = (color.A << 24)
| ((byte)((color.R * a) >> 8) << 16)
| ((byte)((color.G * a) >> 8) << 8)
| ((byte)((color.B * a) >> 8));
for (int i = 0; i < matrix.Length; i++)
{
for (int j = 0; j < matrix.Length; j++)
{
if (matrix[j][i])
{
image.FillRectangle(j * QRCodeScale, i * QRCodeScale, (j + 1) * QRCodeScale, (i + 1) * QRCodeScale, col);
}
}
}
return image;
}
示例14: OnApplyTemplate
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
contentView = GetTemplateChild("ContentView") as Canvas;
double w = (ActualWidth > 0) ? ActualWidth : Width;
double h = (ActualHeight > 0) ? ActualHeight : Height;
double cellWidth = w;
double cellHeight = h / NumBlinds;
// Random brightness
Random randomGenerator = new Random();
List<double> brighenessArray = new List<double>();
for(int i = 0; i < 9; i++)
{
brighenessArray.Add(randomGenerator.Next(10, 30) / 100.0);
}
brighenessArray.Shuffle();
// Create grid elements (always 9 grid)
for (int i = 0; i < NumBlinds; i++)
{
Image cell = new Image();
cell.SetValue(Canvas.TopProperty, i * cellHeight);
cell.SetValue(Canvas.LeftProperty, 0.0);
cell.Width = cellWidth;
cell.Height = cellHeight;
// Fill the cell with a random color
double brightness = brighenessArray[i];
WriteableBitmap backfill = new WriteableBitmap((int)cellWidth, (int)cellHeight);
Color backfillColor = Color.FromArgb(255, 51, 77, 89);
backfillColor = backfillColor.ColorWithBrightness(brightness);
backfill.FillRectangle(0, 0, (int)cellWidth, (int)cellHeight, backfillColor);
cell.Source = backfill;
contentView.Children.Add(cell);
grid.Add(cell);
}
}
示例15: updateOverlay
private static void updateOverlay()
{
Windows.Foundation.Rect unionRect = BarcodeHelper.MWBgetScanningRect(0);
int orientation = BarcodeLib.Scanner.MWBgetDirection();
int width = (int)currentCanvas.ActualWidth;
int height = (int)currentCanvas.ActualHeight;
if (width <= 0 || height == 0)
{
DispatcherTimer updateDelayed = new DispatcherTimer();
updateDelayed.Interval = TimeSpan.FromSeconds(0.2);
updateDelayed.Tick += delegate
{
updateOverlay();
updateDelayed.Stop();
};
updateDelayed.Start();
return;
}
PageOrientation currentOrientation = (((PhoneApplicationFrame)Application.Current.RootVisual).Content as PhoneApplicationPage).Orientation;
if ((currentOrientation & PageOrientation.LandscapeRight) == (PageOrientation.LandscapeRight))
{
unionRect = new Windows.Foundation.Rect(100 - unionRect.Right, 100 -unionRect.Bottom, unionRect.Width, unionRect.Height);
}
else if ((currentOrientation & PageOrientation.PortraitUp) == (PageOrientation.PortraitUp))
{
unionRect = new Windows.Foundation.Rect(100 - unionRect.Top - unionRect.Height, unionRect.Left, unionRect.Height,unionRect.Width);
}
int rectLeft = (int)((float)unionRect.Left * width / 100.0);
int rectTop = (int)((float)unionRect.Top * height / 100.0);
int rectWidth = (int)((float)unionRect.Width * width / 100.0);
int rectHeight = (int)((float)unionRect.Height * height / 100.0);
int rectRight = (int)((float)unionRect.Right * width / 100.0);
int rectBottom = (int)((float)unionRect.Bottom * height / 100.0);
if (isViewportVisible)
{
viewportLayer.Visibility = System.Windows.Visibility.Visible;
var bitmapviewport = new WriteableBitmap(width, height);
bitmapviewport.FillRectangle(0, 0, width, height, colorFromAlphaAndInt(viewportAlpha, 0));
int lineWidth2 = (int)(viewportLineWidth / 2.0);
bitmapviewport.FillRectangle(rectLeft - lineWidth2, rectTop - lineWidth2, rectRight + lineWidth2, rectBottom + lineWidth2, colorFromAlphaAndInt(viewportLineAlpha, viewportLineColor));
bitmapviewport.FillRectangle(rectLeft, rectTop, rectRight, rectBottom, System.Windows.Media.Color.FromArgb(0, 0, 0, 0));
viewportLayer.Source = bitmapviewport;
}
else
{
viewportLayer.Visibility = System.Windows.Visibility.Collapsed;
}
if (isBlinkingLineVisible)
{
lineLayer.Visibility = System.Windows.Visibility.Visible;
addAnimation();
if (width < height)
{
double pos1f = Math.Log(BarcodeLib.Scanner.MWB_SCANDIRECTION_HORIZONTAL) / Math.Log(2);
double pos2f = Math.Log(BarcodeLib.Scanner.MWB_SCANDIRECTION_VERTICAL) / Math.Log(2);
int pos1 = (int)(pos1f + 0.01);
int pos2 = (int)(pos2f + 0.01);
int bit1 = (orientation >> pos1) & 1;// bit at pos1
int bit2 = (orientation >> pos2) & 1;// bit at pos2
int mask = (bit2 << pos1) | (bit1 << pos2);
orientation = orientation & 0xc;
orientation = orientation | mask;
}
//.........这里部分代码省略.........