本文整理汇总了C#中Windows.UI.Xaml.Media.Imaging.WriteableBitmap.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# WriteableBitmap.Clear方法的具体用法?C# WriteableBitmap.Clear怎么用?C# WriteableBitmap.Clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.UI.Xaml.Media.Imaging.WriteableBitmap
的用法示例。
在下文中一共展示了WriteableBitmap.Clear方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnNavigatedTo
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
產生手寫軌跡的測試資料();
solidColorBrush1 = new SolidColorBrush(ColorsHelper.Parse("ff1a1a1a"));
solidColorBrush2 = new SolidColorBrush(ColorsHelper.Parse("ff999999"));
solidColorBrush3 = new SolidColorBrush(ColorsHelper.Parse("ffff0000"));
solidColorBrush4 = new SolidColorBrush(ColorsHelper.Parse("ff006cff"));
solidColorBrush5 = new SolidColorBrush(ColorsHelper.Parse("ff0da522"));
wbContentImage = BitmapFactory.New(768, 1024);
wbContentImage.Clear(Colors.Transparent);
cnUsingWriteableBitmap.Source = wbContentImage;
d2dBrush = new ImageBrush();
cnUsingGeometries.Background = d2dBrush;
// Safely dispose any previous instance
// Creates a new DeviceManager (Direct3D, Direct2D, DirectWrite, WIC)
deviceManager = new DeviceManager();
shapeRenderer = new ShapeRenderer();
DisplayInformation DisplayInformation = Windows.Graphics.Display.DisplayInformation.GetForCurrentView();
int pixelWidth = (int)(cnUsingGeometries.Width * DisplayInformation.LogicalDpi / 96.0);
int pixelHeight = (int)(cnUsingGeometries.Height * DisplayInformation.LogicalDpi / 96.0);
d2dTarget = new SurfaceImageSourceTarget(pixelWidth, pixelHeight);
d2dBrush.ImageSource = d2dTarget.ImageSource;
imgUsingInkManager.Source = d2dTarget.ImageSource;
// Add Initializer to device manager
deviceManager.OnInitialize += d2dTarget.Initialize;
deviceManager.OnInitialize += shapeRenderer.Initialize;
// Render the cube within the CoreWindow
d2dTarget.OnRender += shapeRenderer.Render;
// Initialize the device manager and all registered deviceManager.OnInitialize
deviceManager.Initialize(DisplayProperties.LogicalDpi);
// Setup rendering callback
//CompositionTarget.Rendering += CompositionTarget_Rendering;
// Callback on DpiChanged
DisplayProperties.LogicalDpiChanged += DisplayProperties_LogicalDpiChanged;
#region Scenario1
Scenario1Drawing = new Scenario1ImageSource((int)cnUsingDirectXs.Width, (int)cnUsingDirectXs.Height, true);
// Use Scenario1Drawing as a source for the Ellipse shape's fill
cnUsingDirectXs.Background = new ImageBrush() { ImageSource = Scenario1Drawing };
#endregion
}
示例2: OnNavigatedTo
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
particleBmp = await LoadBitmap("///Assets/FlowerBurst.jpg");
circleBmp = await LoadBitmap("///Assets/circle.png");
particleSourceRect = new Rect(0, 0, 64, 64);
bmp = BitmapFactory.New(640, 480);
bmp.Clear(Colors.Black);
image.Source = bmp;
emitter = new ParticleEmitter();
emitter.TargetBitmap = bmp;
emitter.ParticleBitmap = particleBmp;
CompositionTarget.Rendering += CompositionTarget_Rendering;
this.PointerMoved += MainPage_PointerMoved;
}
示例3: CreateCollage
async Task CreateCollage(IReadOnlyList<StorageFile> files)
{
progressIndicator.Visibility = Windows.UI.Xaml.Visibility.Visible;
var sampleDataGroups = files;
if (sampleDataGroups.Count() == 0) return;
try
{
// Do a square-root of the number of images to get the
// number of images on x and y axis
int number = (int)Math.Ceiling(Math.Sqrt((double)files.Count));
// Calculate the width of each small image in the collage
int numberX = (int)(ImageCollage.ActualWidth / number);
int numberY = (int)(ImageCollage.ActualHeight / number);
// Initialize an empty WriteableBitmap.
WriteableBitmap destination = new WriteableBitmap(numberX * number, numberY * number);
int col = 0; // Current Column Position
int row = 0; // Current Row Position
destination.Clear(Colors.White); // Set the background color of the image to white
WriteableBitmap bitmap; // Temporary bitmap into which the source
// will be copied
foreach (var file in files)
{
// Create RandomAccessStream reference from the current selected image
RandomAccessStreamReference streamRef = RandomAccessStreamReference.CreateFromFile(file);
int wid = 0;
int hgt = 0;
byte[] srcPixels;
// Read the image file into a RandomAccessStream
using (IRandomAccessStreamWithContentType fileStream = await streamRef.OpenReadAsync())
{
// Now that you have the raw bytes, create a Image Decoder
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(fileStream);
// Get the first frame from the decoder because we are picking an image
BitmapFrame frame = await decoder.GetFrameAsync(0);
// Convert the frame into pixels
PixelDataProvider pixelProvider = await frame.GetPixelDataAsync();
// Convert pixels into byte array
srcPixels = pixelProvider.DetachPixelData();
wid = (int)frame.PixelWidth;
hgt = (int)frame.PixelHeight;
// Create an in memory WriteableBitmap of the same size
bitmap = new WriteableBitmap(wid, hgt);
Stream pixelStream = bitmap.PixelBuffer.AsStream();
pixelStream.Seek(0, SeekOrigin.Begin);
// Push the pixels from the original file into the in-memory bitmap
pixelStream.Write(srcPixels, 0, (int)srcPixels.Length);
bitmap.Invalidate();
if (row < number)
{
// Resize the in-memory bitmap and Blit (paste) it at the correct tile
// position (row, col)
destination.Blit(new Rect(col * numberX, row * numberY, numberX, numberY),
bitmap.Resize(numberX, numberY, WriteableBitmapExtensions.Interpolation.Bilinear),
new Rect(0, 0, numberX, numberY));
col++;
if (col >= number)
{
row++;
col = 0;
}
}
}
}
ImageCollage.Source = destination;
((WriteableBitmap)ImageCollage.Source).Invalidate();
progressIndicator.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
}
catch (Exception ex)
{
// TODO: Log Error, unable to render image
throw;
}
}
示例4: LoadWallpaperArt
private async void LoadWallpaperArt()
{
if (_loaded ||
!App.Locator.AppSettingsHelper.Read("WallpaperArt", true, SettingsStrategy.Roaming)) return;
var wait = App.Locator.AppSettingsHelper.Read<int>("WallpaperDayWait");
var created = App.Locator.AppSettingsHelper.ReadJsonAs<DateTime>("WallpaperCreated");
// Set the image brush
var imageBrush = new ImageBrush { Opacity = .25, Stretch = Stretch.UniformToFill, AlignmentY = AlignmentY.Top};
LayoutGrid.Background = imageBrush;
// Once a week remake the wallpaper
if ((DateTime.Now - created).TotalDays > wait)
{
var albums =
App.Locator.CollectionService.Albums.ToList()
.Where(p => p.HasArtwork)
.ToList();
var albumCount = albums.Count;
if (albumCount < 10) return;
var h = Window.Current.Bounds.Height;
var rows = (int) Math.Ceiling(h/(ActualWidth/5));
const int collumns = 5;
var albumSize = (int) Window.Current.Bounds.Width/collumns;
var numImages = rows*5;
var imagesNeeded = numImages - albumCount;
var shuffle = await Task.FromResult(albums
.Shuffle()
.Take(numImages > albumCount ? albumCount : numImages)
.ToList());
if (imagesNeeded > 0)
{
var repeatList = new List<Album>();
while (imagesNeeded > 0)
{
var takeAmmount = imagesNeeded > albumCount ? albumCount : imagesNeeded;
await Task.Run(() => repeatList.AddRange(shuffle.Shuffle().Take(takeAmmount)));
imagesNeeded -= shuffle.Count;
}
shuffle.AddRange(repeatList);
}
// Initialize an empty WriteableBitmap.
var destination = new WriteableBitmap((int) Window.Current.Bounds.Width,
(int) Window.Current.Bounds.Height);
var col = 0; // Current Column Position
var row = 0; // Current Row Position
destination.Clear(Colors.Black); // Set the background color of the image to black
// will be copied
foreach (var artworkPath in shuffle.Select(album => string.Format(AppConstant.ArtworkPath, album.Id)))
{
var file = await WinRtStorageHelper.GetFileAsync(artworkPath);
// Read the image file into a RandomAccessStream
using (var fileStream = await file.OpenReadAsync())
{
try
{
// Now that you have the raw bytes, create a Image Decoder
var decoder = await BitmapDecoder.CreateAsync(fileStream);
// Get the first frame from the decoder because we are picking an image
var frame = await decoder.GetFrameAsync(0);
// Convert the frame into pixels
var pixelProvider = await frame.GetPixelDataAsync();
// Convert pixels into byte array
var srcPixels = pixelProvider.DetachPixelData();
var wid = (int) frame.PixelWidth;
var hgt = (int) frame.PixelHeight;
// Create an in memory WriteableBitmap of the same size
var bitmap = new WriteableBitmap(wid, hgt); // Temporary bitmap into which the source
using (var pixelStream = bitmap.PixelBuffer.AsStream())
{
pixelStream.Seek(0, SeekOrigin.Begin);
// Push the pixels from the original file into the in-memory bitmap
await pixelStream.WriteAsync(srcPixels, 0, srcPixels.Length);
bitmap.Invalidate();
// Resize the in-memory bitmap and Blit (paste) it at the correct tile
// position (row, col)
destination.Blit(new Rect(col*albumSize, row*albumSize, albumSize, albumSize),
bitmap.Resize(albumSize, albumSize, WriteableBitmapExtensions.Interpolation.Bilinear),
new Rect(0, 0, albumSize, albumSize));
//.........这里部分代码省略.........
示例5: CreateCollage
async Task CreateCollage()
{
var sampleDataGroups = this._allGroups;
if (sampleDataGroups.Count() > 0 && sampleDataGroups.ToList()[0].TopItems.Count() == 0) return;
List<TwitterList> list = sampleDataGroups.ToList();
foreach (var currentList in list)
{
try
{
IEnumerable<TweetItem> topItems = currentList.TopItems;
List<Uri> uris = (from tweetItem in topItems
select ((BitmapImage)tweetItem.Image).UriSource).ToList<Uri>();
if (uris.Count > 0)
{
int number = (int)Math.Ceiling(Math.Sqrt((double)uris.Count));
WriteableBitmap destination = new WriteableBitmap(48 * number, 48 * number);
int col = 0;
int row = 0;
destination.Clear(Colors.Transparent);
WriteableBitmap bitmap;
foreach (var uri1 in uris)
{
RandomAccessStreamReference streamRef = RandomAccessStreamReference.CreateFromUri(uri1);
int wid = 0;
int hgt = 0;
byte[] srcPixels;
using (IRandomAccessStreamWithContentType fileStream = await streamRef.OpenReadAsync())
{
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(fileStream);
BitmapFrame frame = await decoder.GetFrameAsync(0);
PixelDataProvider pixelProvider = await frame.GetPixelDataAsync();
srcPixels = pixelProvider.DetachPixelData();
wid = (int)frame.PixelWidth;
hgt = (int)frame.PixelHeight;
bitmap = new WriteableBitmap(wid, hgt);
}
Stream pixelStream1 = bitmap.PixelBuffer.AsStream();
pixelStream1.Seek(0, SeekOrigin.Begin);
pixelStream1.Write(srcPixels, 0, (int)srcPixels.Length);
bitmap.Invalidate();
if (row < number)
{
destination.Blit(new Rect(col * wid, row * hgt, wid, hgt), bitmap, new Rect(0, 0, wid, hgt));
col++;
if (col >= number)
{
row++;
col = 0;
}
}
}
currentList.Image = destination;
((WriteableBitmap)currentList.Image).Invalidate();
}
}
catch (Exception ex)
{
// TODO: Log Error, unable to render image
}
}
}