本文整理汇总了C#中CanvasDevice类的典型用法代码示例。如果您正苦于以下问题:C# CanvasDevice类的具体用法?C# CanvasDevice怎么用?C# CanvasDevice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CanvasDevice类属于命名空间,在下文中一共展示了CanvasDevice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Button_Click
private async void Button_Click(object sender, RoutedEventArgs e)
{
using (var stream = await Root.RenderToRandomAccessStream())
{
var device = new CanvasDevice();
var bitmap = await CanvasBitmap.LoadAsync(device, stream);
var renderer = new CanvasRenderTarget(device, bitmap.SizeInPixels.Width, bitmap.SizeInPixels.Height, bitmap.Dpi);
using (var ds = renderer.CreateDrawingSession())
{
var blur = new GaussianBlurEffect();
blur.BlurAmount = 5.0f;
blur.Source = bitmap;
ds.DrawImage(blur);
}
stream.Seek(0);
await renderer.SaveAsync(stream, CanvasBitmapFileFormat.Png);
BitmapImage image = new BitmapImage();
image.SetSource(stream);
Blured.Source = image;
}
}
示例2: RichListBox
public RichListBox(CanvasDevice device, Vector2 position, int width, int height, string title, CanvasTextFormat titleFont, CanvasTextFormat stringsFont, int maxStrings = 0)
{
// base(device, position, width, 0, title, titleFont)
Position = position;
// title
Title = new CanvasTextLayout(device, title, titleFont, 0, 0);
TitlePosition = new Vector2(Position.X + Padding, Position.Y + Padding);
// width is derived from title bounds
Width = width; //(int)Title.LayoutBounds.Width + Padding * 2;
Height = height;
// bar under title
BarUnderTitleLeft = new Vector2(Position.X, Position.Y + Padding * 2 + (float)Title.LayoutBounds.Height);
BarUnderTitleRight = new Vector2(Position.X + Width, Position.Y + Padding * 2 + (float)Title.LayoutBounds.Height);
// strings
StringsFont = stringsFont;
StringsTextLayout = new CanvasTextLayout(device, "THIS IS A PRETTY GOOD TEMP STRING", StringsFont, 0, 0);
StringsPosition = new Vector2(Position.X + Padding, BarUnderTitleRight.Y + Padding);
MaxStrings = maxStrings == 0 ? 1000 : maxStrings;
BorderRectangle = new Rect(Position.X, Position.Y, Width, Height);
}
示例3: Create
public static World Create(CanvasDevice device, int widthInTiles, int heightInTiles, IProgress<Tuple<string, float>> progress)
{
World world = new World();
ProtoWorld pw = new ProtoWorld(device, widthInTiles, heightInTiles, progress);
while (pw.Aborted) { pw = new ProtoWorld(device, widthInTiles, heightInTiles, progress); }
world.Width = pw.Width;
world.Height = pw.Height;
foreach (ProtoRegion pr in pw.ProtoRegions)
{
world.Regions.Add(Region.FromProtoRegion(pr));
}
foreach (ProtoRegion pcr in pw.ProtoCaves)
{
world.Caves.Add(Region.FromProtoRegion(pcr));
}
world.RenderTargetRegions = pw.RenderTargetRegions;
world.RenderTargetSubregions = pw.RenderTargetSubregions;
world.RenderTargetPaths = pw.RenderTargetPaths;
world.RenderTargetHeightMap = pw.RenderTargetHeightMap;
world.RenderTargetCaves = pw.RenderTargetCaves;
world.RenderTargetCavePaths = pw.RenderTargetCavePaths;
return world;
}
示例4: Append
public void Append(CanvasDevice device, string str)
{
lock (Strings)
{
Strings.Add(device, str);
}
}
示例5: Run
public void Run(IBackgroundTaskInstance taskInstance)
{
using (device = new CanvasDevice())
{
try
{
GenerateTileImage(TileTemplateType.TileSquare150x150Image, 150, 150);
GenerateTileImage(TileTemplateType.TileWide310x150Image, 310, 150);
}
catch (Exception e)
{
if (device.IsDeviceLost(e.HResult))
{
// When the device is lost we don't attempt to retry, and instead just wait for
// the next time the task runs.
return;
}
// Any other errors we bubble up
throw;
}
}
UpdateLiveTiles();
DeleteOldLiveTileImageFiles();
LiveTileUpdater.SetLatestTileImagesInSettings(tiles.Values);
}
示例6: win2d_TextboxCursor
public win2d_TextboxCursor(CanvasDevice device, Color color)
{
Color = color;
LastUpdate = TimeSpan.Zero;
CursorCharacter = new CanvasTextLayout(device, "|", Statics.DefaultFontNoWrap, 0, 0);
}
示例7: win2d_Button
public win2d_Button(CanvasDevice device, Vector2 position, int width, int height, string text)
: base(position, width, height)
{
Color = Colors.Gray;
TextLayout = new CanvasTextLayout(device, text, Statics.DefaultFontNoWrap, 0, 0);
RecalculateLayout();
}
示例8: MultithreadedSaveToFile
public void MultithreadedSaveToFile()
{
//
// This test can create a deadlock if the SaveAsync code holds on to the
// ID2D1Multithread resource lock longer than necessary.
//
// A previous implementation waited until destruction of the IAsyncAction before calling Leave().
// In managed code this can happen on an arbitrary thread and so could result in deadlock situations
// where other worker threads were waiting for a Leave on the original thread that never arrived.
//
using (new DisableDebugLayer()) // 6184116 causes the debug layer to fail when CanvasBitmap::SaveAsync is called
{
var task = Task.Run(async () =>
{
var device = new CanvasDevice();
var rt = new CanvasRenderTarget(device, 16, 16, 96);
var filename = Path.Combine(ApplicationData.Current.TemporaryFolder.Path, "testfile.jpg");
await rt.SaveAsync(filename);
rt.Dispose();
});
task.Wait();
}
}
示例9: win2d_TextblockStringCollection
public win2d_TextblockStringCollection(CanvasDevice device, Vector2 position, int drawingwidth, int drawingheight, bool scrolltobottomonappend = false)
{
_device = device;
Position = position;
DrawingWidth = drawingwidth;
DrawingHeight = drawingheight;
ScrollToBottomOnAppend = scrolltobottomonappend;
}
示例10: CreateResources
private void CreateResources(Size sizeSwapchain)
{
_device = new CanvasDevice();
_swapchain = new CanvasSwapChain(_device, (float)sizeSwapchain.Width, (float)sizeSwapchain.Height, 96);
// Start rendering the swapchain
StartRendering(sizeSwapchain);
}
示例11: CreateFromBuffer
public void CreateFromBuffer()
{
var device = new CanvasDevice();
byte[] somePixelData = { 1, 2, 3, 4 };
var buffer = somePixelData.AsBuffer();
// Overload #1
var bitmap = CanvasBitmap.CreateFromBytes(device, buffer, 2, 2, DirectXPixelFormat.A8UIntNormalized);
Assert.AreEqual(2u, bitmap.SizeInPixels.Width);
Assert.AreEqual(2u, bitmap.SizeInPixels.Height);
Assert.AreEqual(96, bitmap.Dpi);
Assert.AreEqual(DirectXPixelFormat.A8UIntNormalized, bitmap.Format);
Assert.AreEqual(CanvasAlphaMode.Premultiplied, bitmap.AlphaMode);
CollectionAssert.AreEqual(somePixelData, bitmap.GetPixelBytes());
// Overload #2
const float someDpi = 123.0f;
bitmap = CanvasBitmap.CreateFromBytes(device, buffer, 2, 2, DirectXPixelFormat.A8UIntNormalized, someDpi);
Assert.AreEqual(2u, bitmap.SizeInPixels.Width);
Assert.AreEqual(2u, bitmap.SizeInPixels.Height);
Assert.AreEqual(someDpi, bitmap.Dpi);
Assert.AreEqual(DirectXPixelFormat.A8UIntNormalized, bitmap.Format);
Assert.AreEqual(CanvasAlphaMode.Premultiplied, bitmap.AlphaMode);
CollectionAssert.AreEqual(somePixelData, bitmap.GetPixelBytes());
// Overload #3
bitmap = CanvasBitmap.CreateFromBytes(device, buffer, 2, 2, DirectXPixelFormat.A8UIntNormalized, someDpi, CanvasAlphaMode.Straight);
Assert.AreEqual(2u, bitmap.SizeInPixels.Width);
Assert.AreEqual(2u, bitmap.SizeInPixels.Height);
Assert.AreEqual(someDpi, bitmap.Dpi);
Assert.AreEqual(DirectXPixelFormat.A8UIntNormalized, bitmap.Format);
Assert.AreEqual(CanvasAlphaMode.Straight, bitmap.AlphaMode);
CollectionAssert.AreEqual(somePixelData, bitmap.GetPixelBytes());
// Null device.
Assert.ThrowsException<ArgumentException>(() => CanvasBitmap.CreateFromBytes(null, buffer, 2, 2, DirectXPixelFormat.A8UIntNormalized));
Assert.ThrowsException<ArgumentException>(() => CanvasBitmap.CreateFromBytes(null, buffer, 2, 2, DirectXPixelFormat.A8UIntNormalized, someDpi));
Assert.ThrowsException<ArgumentException>(() => CanvasBitmap.CreateFromBytes(null, buffer, 2, 2, DirectXPixelFormat.A8UIntNormalized, someDpi, CanvasAlphaMode.Straight));
// Null buffer.
IBuffer nullBuffer = null;
Assert.ThrowsException<ArgumentException>(() => CanvasBitmap.CreateFromBytes(device, nullBuffer, 2, 2, DirectXPixelFormat.A8UIntNormalized));
Assert.ThrowsException<ArgumentException>(() => CanvasBitmap.CreateFromBytes(device, nullBuffer, 2, 2, DirectXPixelFormat.A8UIntNormalized, someDpi));
Assert.ThrowsException<ArgumentException>(() => CanvasBitmap.CreateFromBytes(device, nullBuffer, 2, 2, DirectXPixelFormat.A8UIntNormalized, someDpi, CanvasAlphaMode.Straight));
// Too small a buffer.
Assert.ThrowsException<ArgumentException>(() => CanvasBitmap.CreateFromBytes(device, buffer, 3, 3, DirectXPixelFormat.A8UIntNormalized));
}
示例12: Initialize
public static void Initialize(CanvasDevice device)
{
LoadCharacterWidths(device);
UpArrow = new CanvasTextLayout(device, "\u2191", Statics.DefaultFontNoWrap, 0, 0);
DoubleUpArrow = new CanvasTextLayout(device, "\u219f", Statics.DefaultFontNoWrap, 0, 0);
DownArrow = new CanvasTextLayout(device, "\u2193", Statics.DefaultFontNoWrap, 0, 0);
DoubleDownArrow = new CanvasTextLayout(device, "\u21a1", Statics.DefaultFontNoWrap, 0, 0);
}
示例13: FeedItemLayoutData
public FeedItemLayoutData(CanvasDevice device, FeedItem feedItem, float fRequestedWidth)
{
FeedDataTitleLayout = new CanvasTextLayout(device, feedItem.FeedDataTitle, Statics.DefaultFont, fRequestedWidth, 20);
PublicationDateLayout = new CanvasTextLayout(device, feedItem.PublicationDate.ToString("MM/dd/yy"), Statics.DefaultFont, fRequestedWidth, 20); // MMMM dd, yyyy - h:mm
TitleLayout = new CanvasTextLayout(device, feedItem.Title, Statics.DefaultFont, fRequestedWidth, 20);
AuthorLayout = new CanvasTextLayout(device, feedItem.Author, Statics.DefaultFont, fRequestedWidth, 20);
if (feedItem.Title != feedItem.Content) { ContentLayout = new CanvasTextLayout(device, feedItem.Content, Statics.DefaultFont, fRequestedWidth, 20); }
LinkLayout = new CanvasTextLayout(device, feedItem.Link.ToString(), Statics.DefaultFont, fRequestedWidth, 20);
}
示例14: win2d_Textblock
public win2d_Textblock(CanvasDevice device, Vector2 position, int width, int height, bool scrolltobottomonappend = false)
: base(position, width, height)
{
_device = device;
Strings = new win2d_TextblockStringCollection(_device, new Vector2(Position.X + PaddingX, Position.Y + PaddingY),
Width - PaddingY * 2,
Height - PaddingY * 2,
scrolltobottomonappend);
}
示例15: SSD1603
/// <summary>
/// constructor
/// </summary>
/// <param name="config"></param>
private SSD1603(SSD1603Configuration config, BusTypes bus)
{
Configuration = config;
BusType = bus;
//for drawing
_canvasDevice = CanvasDevice.GetSharedDevice();
Render = new CanvasRenderTarget(_canvasDevice, Screen.WidthInDIP, Screen.HeightInDIP, Screen.DPI,
Windows.Graphics.DirectX.DirectXPixelFormat.A8UIntNormalized, CanvasAlphaMode.Straight);
}