本文整理汇总了C#中System.Windows.Media.Imaging.WriteableBitmap.Invalidate方法的典型用法代码示例。如果您正苦于以下问题:C# WriteableBitmap.Invalidate方法的具体用法?C# WriteableBitmap.Invalidate怎么用?C# WriteableBitmap.Invalidate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.Imaging.WriteableBitmap
的用法示例。
在下文中一共展示了WriteableBitmap.Invalidate方法的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: 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);
}
示例3: OnNavigatedTo
protected override async void OnNavigatedTo(NavigationEventArgs e) {
StreamResourceInfo sri = Application.GetResourceStream(new Uri("DemoImage.jpg", UriKind.Relative));
var myBitmap = new WriteableBitmap(800, 480);
img.ImageSource = myBitmap;
using (var editsession = await EditingSessionFactory.CreateEditingSessionAsync(sri.Stream)) {
// First add an antique effect
editsession.AddFilter(FilterFactory.CreateCartoonFilter(true));
editsession.AddFilter(FilterFactory.CreateAntiqueFilter());
// Then rotate the image
editsession.AddFilter(FilterFactory.CreateFreeRotationFilter(35.0f, RotationResizeMode.FitInside));
await editsession.RenderToBitmapAsync(myBitmap.AsBitmap());
}
myBitmap.Invalidate();
base.OnNavigatedTo(e);
}
示例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: 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;
}
示例6: 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;
}
示例7: ToImage
public static ImageTools.Image ToImage(WriteableBitmap bitmap)
{
bitmap.Invalidate();
ImageTools.Image image = new ImageTools.Image(bitmap.PixelWidth, bitmap.PixelHeight);
try
{
for (int y = 0; y < bitmap.PixelHeight; ++y)
{
for (int x = 0; x < bitmap.PixelWidth; ++x)
{
int pixel = bitmap.Pixels[bitmap.PixelWidth * y + x];
byte a = (byte)((pixel >> 24) & 0xFF);
float aFactor = a / 255f;
byte r = (byte)(((pixel >> 16) & 0xFF) / aFactor);
byte g = (byte)(((pixel >> 8) & 0xFF) / aFactor);
byte b = (byte)((pixel & 0xFF) / aFactor);
image.SetPixel(x, y, r, g, b, a);
}
}
}
catch (System.Security.SecurityException e)
{
throw new ArgumentException("Bitmap cannot accessed", e);
}
return image;
}
示例8: 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();
}
}
示例9: 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);
}
}
示例10: 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);
}
}
示例11: Button_Click
private void Button_Click(object sender, RoutedEventArgs e)
{
Uri fileUri = new Uri(string.Format("Assets/{0}.webp", "unnamed"), UriKind.Relative);
StreamResourceInfo res = Application.GetResourceStream(fileUri);
if (res != null && res.Stream != null)
{
using (MemoryStream stream = new MemoryStream())
{
CopyStream(res.Stream, stream);
WebpComponent.WebpRuntimeComponent com = new WebpComponent.WebpRuntimeComponent();
byte[] arr = stream.GetBuffer();
var result = com.DecodeRGBA(arr, arr.Length, 128, 128);
WriteableBitmap bitmap = new WriteableBitmap(128, 128);
for (int i = 0; i < result.Length; i+=4)
{
// make the transform from color to pixel.
int tranformedPixel = (result[i + 3] << 24 | result[i] << 16 | result[i + 1] << 8 | result[i + 2]);
bitmap.Pixels[i/4] = tranformedPixel;
}
bitmap.Invalidate();
image.Source = bitmap;
}
}
}
示例12: 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;
}
示例13: MainPage
public MainPage()
{
InitializeComponent();
bmp = new WriteableBitmap(2*640, 2*480);
fractalImage.Source = bmp;
Fractals.WriteMandelbrot(bmp);
bmp.Invalidate();
}
示例14: MainPage
public MainPage()
{
InitializeComponent();
this.Width = 600;
this.Height = 600;
var i = new Image();
//var s = new WriteableBitmap(600, 600, 96, 96, PixelFormats.Pbgra32, null);
var s = new WriteableBitmap(600, 600, PixelFormats.Pbgra32);
Plasma.generatePlasma(600, 600);
var shift = 0;
Action Refresh =
delegate
{
var buffer = Plasma.shiftPlasma(shift);
s.Lock();
for (int j = 0; j < buffer.Length; j++)
{
//Marshal.WriteInt32(s.BackBuffer, j * 4, unchecked((int)(buffer[j] | 0xff000000)));
s[j] = unchecked((int)(buffer[j] | 0xff000000));
}
//s.AddDirtyRect(new Int32Rect(0, 0, 600, 600));
s.Invalidate();
s.Unlock();
};
var t = new DispatcherTimer();
t.Tick +=
delegate
{
shift++;
Refresh();
};
t.Interval = TimeSpan.FromMilliseconds(50);
t.Start();
Refresh();
i.Source = s;
this.Content = i;
}
示例15: ReplaceImage
private void ReplaceImage()
{
try
{
// Explicitly size the control - for use in a background agent
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(LayoutRoot, null);
wb.Invalidate();
// Create a filename for JPEG file in isolated storage.
String fileName = "Lock_" + Guid.NewGuid().ToString() + ".jpg";
var myStore = IsolatedStorageFile.GetUserStoreForApplication();
using (IsolatedStorageFileStream myFileStream = myStore.CreateFile(fileName))
{
// Encode WriteableBitmap object to a JPEG stream.
wb.SaveJpeg(myFileStream, wb.PixelWidth, wb.PixelHeight, 0, 75);
myFileStream.Close();
}
// Delete images from earlier execution
var filesTodelete = from f in myStore.GetFileNames("Lock_*").AsQueryable()
where f != fileName
select f;
foreach (var file in filesTodelete)
{
myStore.DeleteFile(file);
}
// Fire completion event
if (SaveJpegComplete != null)
{
SaveJpegComplete(this, new SaveJpegCompleteEventArgs(true, fileName));
MessageBox.Show("Lock screen changed!");
}
}
catch (Exception ex)
{
// Log it
System.Diagnostics.Debug.WriteLine("Exception in SaveJpeg: " + ex.ToString());
if (SaveJpegComplete != null)
{
var args1 = new SaveJpegCompleteEventArgs(false, "");
args1.Exception = ex;
SaveJpegComplete(this, args1);
}
}
}