本文整理汇总了C#中System.Windows.Media.Imaging.WriteableBitmap.Render方法的典型用法代码示例。如果您正苦于以下问题:C# WriteableBitmap.Render方法的具体用法?C# WriteableBitmap.Render怎么用?C# WriteableBitmap.Render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.Imaging.WriteableBitmap
的用法示例。
在下文中一共展示了WriteableBitmap.Render方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public static Uri Create(string filename, string text, SolidColorBrush backgroundColor, double textSize, Size size)
{
var background = new Rectangle();
background.Width = size.Width;
background.Height = size.Height;
background.Fill = backgroundColor;
var textBlock = new TextBlock();
textBlock.Width = 500;
textBlock.Height = 500;
textBlock.TextWrapping = TextWrapping.Wrap;
textBlock.Text = text;
textBlock.FontSize = textSize;
textBlock.Foreground = new SolidColorBrush(Colors.White);
textBlock.FontFamily = new FontFamily("Segoe WP");
var tileImage = "/Shared/ShellContent/" + filename;
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
var bitmap = new WriteableBitmap((int)size.Width, (int)size.Height);
bitmap.Render(background, new TranslateTransform());
bitmap.Render(textBlock, new TranslateTransform() { X = 39, Y = 88 });
var stream = store.CreateFile(tileImage);
bitmap.Invalidate();
bitmap.SaveJpeg(stream, (int)size.Width, (int)size.Height, 0, 99);
stream.Close();
}
return new Uri("ms-appdata:///local" + tileImage, UriKind.Absolute);
}
示例2: PrintToPngFile
/// <summary>
/// The print to png file.
/// </summary>
/// <param name="canvas1">
/// The canvas 1.
/// </param>
/// <param name="canvas2">
/// The canvas 2.
/// </param>
/// <param name="canvas3">
/// The canvas 3.
/// </param>
/// <param name="canvas4">
/// The canvas 4.
/// </param>
/// <param name="stream">
/// The stream.
/// </param>
/// <returns>
/// The <see cref="BitmapSource"/>.
/// </returns>
public static BitmapSource PrintToPngFile(
Canvas canvas1, Canvas canvas2, Canvas canvas3, Canvas canvas4, Stream stream)
{
var wb =
new WriteableBitmap(
(int)Math.Round(canvas1.ActualWidth, 0) + (int)Math.Round(canvas2.ActualWidth, 0),
(int)Math.Round(canvas1.ActualHeight, 0) + (int)Math.Round(canvas3.ActualHeight, 0));
wb.Render(canvas1, null);
wb.Render(canvas2, new TranslateTransform { X = canvas1.ActualWidth, Y = 0 });
wb.Render(canvas3, new TranslateTransform { X = 0, Y = canvas1.ActualHeight });
wb.Render(canvas4, new TranslateTransform { X = canvas1.ActualWidth, Y = canvas2.ActualHeight });
wb.Invalidate();
var g = new PngGenerator(wb.PixelWidth, wb.PixelHeight);
var colors = new Color[wb.PixelWidth * wb.PixelHeight];
int i = 0;
foreach (int p in wb.Pixels)
{
byte[] bytes = BitConverter.GetBytes(p);
Color c = Color.FromArgb(bytes[3], bytes[2], bytes[1], bytes[0]);
colors[i] = c;
i++;
}
g.SetPixelColorData(colors);
Stream pngStream = g.CreateStream();
pngStream.CopyTo(stream);
stream.Close();
return wb;
}
示例3: RenderTile
private static void RenderTile(WriteableBitmap bitmap, ITileSchema schema, IViewport viewport, MemoryCache<Feature> memoryCache)
{
int level = BruTile.Utilities.GetNearestLevel(schema.Resolutions, viewport.Resolution);
var tiles = schema.GetTilesInView(viewport.Extent.ToExtent(), level);
foreach (TileInfo tile in tiles)
{
var p = NativeCache.Find(tile.Index);
if (p != null)
{
bitmap.Render(p, null);
continue;
}
var image = memoryCache.Find(tile.Index);
if (image != null)
{
Rect dest = WorldToView(tile.Extent, viewport);
dest = GeometryRenderer.RoundToPixel(dest);
//See here the clumsy way to write a bitmap in SL/WPF
var path = new System.Windows.Shapes.Path();
path.Data = new RectangleGeometry { Rect = dest };
var bitmapImage = new BitmapImage();
bitmapImage.SetSource(((IRaster)image.Geometry).Data);
path.Fill = new ImageBrush { ImageSource = bitmapImage };
path.CacheMode = new BitmapCache();
bitmap.Render(path, null);
}
}
}
示例4: task_Completed
void task_Completed(object sender, PhotoResult e)
{
if(e.TaskResult == TaskResult.OK)
{
var bmp = new WriteableBitmap(0,0);
bmp.SetSource(e.ChosenPhoto);
var bmpres = new WriteableBitmap(bmp.PixelWidth,bmp.PixelHeight);
var txt = new WindowsPhoneControl1();
txt.Text = txtInput.Text;
txt.FontSize = 36 * bmpres.PixelHeight / 480;
txt.Width = bmpres.PixelWidth;
txt.Height = bmpres.PixelHeight;
//should call Measure and when uicomponent is not in visual tree
txt.Measure(new Size(bmpres.PixelWidth, bmpres.PixelHeight));
txt.Arrange(new Rect(0, 0, bmpres.PixelWidth, bmpres.PixelHeight));
bmpres.Render(new Image() { Source = bmp }, null);
bmpres.Render(txt, null);
bmpres.Invalidate();
display.Source = bmpres;
}
}
示例5: Create
public static Uri Create(string filename, string text, ImageSource img, SolidColorBrush backgroundColor, double textSize, bool titleClear, Size tileSize)
{
var background = new Rectangle();
background.Width = tileSize.Width;
background.Height = tileSize.Height;
background.Fill = backgroundColor;
var image = new Image();
image.Source = img;
image.Width = tileSize.Width - 4;
image.Height = tileSize.Height - 4;
image.Stretch = Stretch.Uniform;
TextBlock textBlock = new TextBlock();
textBlock.Width = tileSize.Width - 30;
textBlock.Height = tileSize.Height - 30;
textBlock.TextWrapping = TextWrapping.Wrap;
textBlock.Text = text;
textBlock.FontSize = textSize;
textBlock.Foreground = new SolidColorBrush(img != null ? Colors.Black : Colors.White);
textBlock.FontFamily = new FontFamily("Segoe WP");
var textShadow = new Rectangle();
textShadow.Width = textBlock.ActualWidth + 12;
textShadow.Height = textBlock.ActualHeight + 12;
textShadow.Opacity = 0.8;
textShadow.Fill = new SolidColorBrush(Colors.White);
var titleShadow = new Rectangle();
titleShadow.Width = tileSize.Width;
titleShadow.Height = 50;
titleShadow.Opacity = 0.7;
titleShadow.Fill = backgroundColor;
var tileImage = "/Shared/ShellContent/" + filename;
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
var bitmap = new WriteableBitmap((int)tileSize.Width, (int)tileSize.Height);
bitmap.Render(background, new TranslateTransform());
bitmap.Render(image, new TranslateTransform() { X = 2, Y = 2 });
if (img != null) bitmap.Render(textShadow, new TranslateTransform() { X = 5 - 2, Y = 5 - 2 });
bitmap.Render(textBlock, new TranslateTransform() { X = 15, Y = 5 });
if (titleClear) bitmap.Render(titleShadow, new TranslateTransform() { X = 0, Y = tileSize.Height - titleShadow.Height });
var stream = store.CreateFile(tileImage);
bitmap.Invalidate();
bitmap.SaveJpeg(stream, (int)tileSize.Width, (int)tileSize.Height, 0, 99);
stream.Close();
}
return new Uri("isostore:" + tileImage, UriKind.Absolute);
}
示例6: CreateImage
public static void CreateImage(string code, Image image, int width, int height)
{
Color[] colors = { Colors.Black, Colors.Red, Colors.Blue, Colors.Green,
Colors.Orange, Colors.Brown, Colors.Brown };
StackPanel stackPanel = new StackPanel();
stackPanel.Orientation = Orientation.Horizontal;
stackPanel.HorizontalAlignment = HorizontalAlignment.Center;
stackPanel.VerticalAlignment = VerticalAlignment.Center;
stackPanel.Margin = new Thickness(4);
Random random = new Random(Guid.NewGuid().GetHashCode());
for (int codeNumber = 0; codeNumber < code.Length; codeNumber++)
{
TextBlock textBlock = DrawCodes(code, colors, random, codeNumber);
stackPanel.Children.Add(textBlock);
}
//for (int lineNumber = 0; lineNumber < 10; lineNumber++)
//{
// Polyline line = DrawLines(width, height, colors, random);
// stackPanel.Children.Add(line);
//}
WriteableBitmap writeableBitmap = new WriteableBitmap(stackPanel, new TransformGroup());
writeableBitmap.Render(stackPanel, new TransformGroup());
image.Source = writeableBitmap;
}
示例7: capture
public static Boolean capture(int quality)
{
try
{
PhoneApplicationFrame frame = (PhoneApplicationFrame)Application.Current.RootVisual;
WriteableBitmap bitmap = new WriteableBitmap((int)frame.ActualWidth, (int)frame.ActualHeight);
bitmap.Render(frame, null);
bitmap.Invalidate();
string fileName = DateTime.Now.ToString("'Capture'yyyyMMddHHmmssfff'.jpg'");
IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
if (storage.FileExists(fileName))
return false;
IsolatedStorageFileStream stream = storage.CreateFile(fileName);
bitmap.SaveJpeg(stream, bitmap.PixelWidth, bitmap.PixelHeight, 0, quality);
stream.Close();
stream = storage.OpenFile(fileName, FileMode.Open, FileAccess.Read);
MediaLibrary mediaLibrary = new MediaLibrary();
Picture picture = mediaLibrary.SavePicture(fileName, stream);
stream.Close();
storage.DeleteFile(fileName);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return false;
}
return true;
}
示例8: ToBitmapStream
public static MemoryStream ToBitmapStream(Canvas canvas, int width, int height)
{
var writeableBitmap = new WriteableBitmap(width, height);
writeableBitmap.Render(canvas, null);
writeableBitmap.Invalidate();
return ToBitmapStream(writeableBitmap);
}
示例9: LoadBitmap
static public Texture2D LoadBitmap(string imageName, int w, int h)
{
//
// Load a bitmap image through writeablebitmap so that we can populate our device
// texture
//
StreamResourceInfo sr = Application.GetResourceStream(new Uri(imageName, UriKind.Relative));
BitmapImage bs = new BitmapImage();
bs.SetSource(sr.Stream);
var wb = new WriteableBitmap(w, h);
ScaleTransform t = new ScaleTransform();
t.ScaleX = (double)w / (double)bs.PixelWidth;
t.ScaleY = (double)h / (double)bs.PixelHeight;
Image image = new Image();
image.Source = bs;
wb.Render(image, t);
wb.Invalidate();
Texture2D tex = new Texture2D(GraphicsDeviceManager.Current.GraphicsDevice, wb.PixelWidth, wb.PixelHeight, false, SurfaceFormat.Color);
wb.CopyTo(tex);
return tex;
}
示例10: SaveTile
public void SaveTile(bool failed, UserBalance balance, string backcontent, string path)
{
try
{
var color = (bool)IsolatedStorageSettings.ApplicationSettings["tileAccentColor"]
? (SolidColorBrush)Application.Current.Resources["PhoneAccentBrush"]
: new SolidColorBrush(new Color { A = 255, R = 150, G = 8, B = 8 });
var tile = GetElement();
tile.Measure(new Size(336, 336));
tile.Arrange(new Rect(0, 0, 336, 336));
var bmp = new WriteableBitmap(336, 336);
bmp.Render(tile, null);
bmp.Invalidate();
using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!isf.DirectoryExists("/CustomLiveTiles"))
{
isf.CreateDirectory("/CustomLiveTiles");
}
using (var stream = isf.OpenFile(path, FileMode.OpenOrCreate))
{
bmp.SaveJpeg(stream, 336, 366, 0, 100);
}
}
}
catch (Exception)
{
//sleep for 0.5 seconds in order to try to resolve the isolatedstorage issues
Thread.Sleep(500);
SaveTile(failed, balance, backcontent, path);
}
}
示例11: DoCapture
public byte[] DoCapture()
{
FrameworkElement toSnap = null;
if (!AutomationIdIsEmpty)
toSnap = GetFrameworkElement(false);
if (toSnap == null)
toSnap = AutomationElementFinder.GetRootVisual();
if (toSnap == null)
return null;
// Save to bitmap
var bmp = new WriteableBitmap((int)toSnap.ActualWidth, (int)toSnap.ActualHeight);
bmp.Render(toSnap, null);
bmp.Invalidate();
// Get memoryStream from bitmap
using (var memoryStream = new MemoryStream())
{
bmp.SaveJpeg(memoryStream, bmp.PixelWidth, bmp.PixelHeight, 0, 95);
memoryStream.Seek(0, SeekOrigin.Begin);
return memoryStream.GetBuffer();
}
}
示例12: Save
private async Task Save()
{
this.UpdateLayout();
this.Measure(new Size(480, 800));
this.UpdateLayout();
this.Arrange(new Rect(0, 0, 480, 800));
var wb = new WriteableBitmap(480, 800);
wb.Render(this, null);
wb.Invalidate();
using (var stream = new MemoryStream())
{
wb.SaveJpeg(stream, 480, 800, 0, 75);
stream.Seek(0, SeekOrigin.Begin);
fileName = "Lock_" + Guid.NewGuid().ToString() + ".jpg";
await SaveToLocalFolderAsync(stream, fileName);
}
if (HasImage)
{
Uri uri_UI = new Uri("ms-appdata:///Local/" + fileName, UriKind.RelativeOrAbsolute);
Windows.Phone.System.UserProfile.LockScreen.SetImageUri(uri_UI);
}
}
示例13: CreateFramedAnimation
private static IReadOnlyList<IImageProvider> CreateFramedAnimation(IReadOnlyList<IImageProvider> images, Rect animationBounds, int w, int h)
{
List<IImageProvider> framedAnimation = new List<IImageProvider>();
WriteableBitmap maskBitmap = new WriteableBitmap(w, h);
var backgroundRectangle = new Rectangle
{
Fill = new SolidColorBrush(Colors.Black),
Width = w,
Height = h,
};
maskBitmap.Render(backgroundRectangle, new TranslateTransform());
var foregroundRectangle = new Rectangle
{
Fill = new SolidColorBrush(Colors.White),
Width = animationBounds.Width,
Height = animationBounds.Height,
};
TranslateTransform foregroundTranslate = new TranslateTransform
{
X = animationBounds.X,
Y = animationBounds.Y
};
maskBitmap.Render(foregroundRectangle, foregroundTranslate);
maskBitmap.Invalidate();
foreach (IImageProvider frame in images)
{
FilterEffect filterEffect = new FilterEffect(images[0]);
BlendFilter blendFilter = new BlendFilter(frame, BlendFunction.Normal, 1.0)
{
MaskSource = new BitmapImageSource(maskBitmap.AsBitmap())
};
filterEffect.Filters = new List<IFilter>() { blendFilter };
framedAnimation.Add(filterEffect);
}
return framedAnimation;
}
示例14: Render
public void Render(string text, int x, int y, int size, Color foreground, WriteableBitmap screen)
{
textSource.Text = text;
textSource.FontSize = size;
(textSource.Foreground as SolidColorBrush).Color = foreground;
textTranslate.X = x;
textTranslate.Y = y;
screen.Render(textSource, textTranslate);
}
示例15: SaveButton_Click
private void SaveButton_Click(object sender, EventArgs e)
{
WriteableBitmap wb = new WriteableBitmap(mapControl, null);
wb.Render(mapControl, null);
MemoryStream memoryStream = new MemoryStream();
wb.SaveJpeg(memoryStream, wb.PixelWidth, wb.PixelHeight, 0, 80);
MediaLibrary library = new MediaLibrary();
library.SavePictureToCameraRoll("SavedMap_" + DateTime.Now.ToString() + ".jpg", memoryStream.GetBuffer());
}