本文整理汇总了C#中System.Windows.Media.Imaging.WriteableBitmap类的典型用法代码示例。如果您正苦于以下问题:C# WriteableBitmap类的具体用法?C# WriteableBitmap怎么用?C# WriteableBitmap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WriteableBitmap类属于System.Windows.Media.Imaging命名空间,在下文中一共展示了WriteableBitmap类的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: Render
private void Render(DrawingContext drawingContext)
{
if (_width > 0 && _height > 0)
{
if (_bitmap == null || _bitmap.Width != _width || _bitmap.Height != _height)
{
_bitmap = new WriteableBitmap(_width, _height, 96, 96, PixelFormats.Pbgra32, null);
}
_bitmap.Lock();
using (var surface = SKSurface.Create(_width, _height, SKImageInfo.PlatformColorType, SKAlphaType.Premul, _bitmap.BackBuffer, _bitmap.BackBufferStride))
{
var canvas = surface.Canvas;
canvas.Scale((float)_dpiX, (float)_dpiY);
canvas.Clear();
using (new SKAutoCanvasRestore(canvas, true))
{
Presenter.Render(canvas, Renderer, Container, _offsetX, _offsetY);
}
}
_bitmap.AddDirtyRect(new Int32Rect(0, 0, _width, _height));
_bitmap.Unlock();
drawingContext.DrawImage(_bitmap, new Rect(0, 0, _actualWidth, _actualHeight));
}
}
示例3: SaveTileBackgroundImage
private static void SaveTileBackgroundImage(TileViewModel model)
{
string xamlCode;
using (var tileStream = Application.GetResourceStream(new Uri("/WP7LiveTileDemo;component/Controls/CustomTile.xaml", UriKind.Relative)).Stream)
{
using (var reader = new StreamReader(tileStream))
{
xamlCode = reader.ReadToEnd();
}
}
var control = (Control)XamlReader.Load(xamlCode);
control.DataContext = model;
var bitmap = new WriteableBitmap(173, 173);
bitmap.Render(control, new TranslateTransform());
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
using (var stream = store.CreateFile(TileBackgroundPath))
{
bitmap.Invalidate();
bitmap.SaveJpeg(stream, 173, 173, 0, 100);
stream.Close();
}
}
}
示例4: RenderTargetImageSource
/// <summary>
/// Creates a new RenderTargetImageSource.
/// </summary>
/// <param name="graphics">The GraphicsDevice to use.</param>
/// <param name="width">The width of the image source.</param>
/// <param name="height">The height of the image source.</param>
public RenderTargetImageSource(GraphicsDevice graphics, int width, int height)
{
// create the render target and buffer to hold the data
renderTarget = new RenderTarget2D(graphics, width, height, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8);
buffer = new byte[width * height * 4];
writeableBitmap = new WriteableBitmap(width, height, 96, 96, PixelFormats.Bgra32, null);
}
示例5: CaptureImageCompletedEventArgs
public CaptureImageCompletedEventArgs (WriteableBitmap image)
: base (null, false, null)
{
// Note: When this is implemented a native peer will have to be created.
Console.WriteLine ("NIEX: System.Windows.Media.CaptureImageCompletedEventArgs:.ctor");
throw new NotImplementedException ();
}
示例6: ToBitmap
/// <summary>
/// Converts a color frame to a System.Media.Imaging.BitmapSource.
/// </summary>
/// <param name="frame">The specified color frame.</param>
/// <returns>The specified frame in a System.Media.Imaging.BitmapSource representation of the color frame.</returns>
public static BitmapSource ToBitmap(this ColorFrame frame)
{
if (_bitmap == null)
{
_width = frame.FrameDescription.Width;
_height = frame.FrameDescription.Height;
_pixels = new byte[_width * _height * Constants.BYTES_PER_PIXEL];
_bitmap = new WriteableBitmap(_width, _height, Constants.DPI, Constants.DPI, Constants.FORMAT, null);
}
if (frame.RawColorImageFormat == ColorImageFormat.Bgra)
{
frame.CopyRawFrameDataToArray(_pixels);
}
else
{
frame.CopyConvertedFrameDataToArray(_pixels, ColorImageFormat.Bgra);
}
_bitmap.Lock();
Marshal.Copy(_pixels, 0, _bitmap.BackBuffer, _pixels.Length);
_bitmap.AddDirtyRect(new Int32Rect(0, 0, _width, _height));
_bitmap.Unlock();
return _bitmap;
}
示例7: plotButton_click
private void plotButton_click(object sender, RoutedEventArgs e)
{
if (graphBitmap == null)
{
graphBitmap = new WriteableBitmap(pixelWidth, pixelHeight, dpiX, dpiY, PixelFormats.Gray8, null);
}
Action doPlotButtonWorkAction = new Action(doPlotButtonWork);
doPlotButtonWorkAction.BeginInvoke(null, null);
#region 注释掉的内容
//int byetePerPixel = (graphBitmap.Format.BitsPerPixel + 7) / 8;
//int stride = byetePerPixel * graphBitmap.PixelWidth;
//int dataSize = stride * graphBitmap.PixelHeight;
//byte[] data = new byte[dataSize];
//Stopwatch watch = new Stopwatch();
////generateGraphData(data);
////新建线程
//Task first = Task.Factory.StartNew(()=>generateGraphData(data,0,pixelWidth/8));
//Task second = Task.Factory.StartNew(() => generateGraphData(data, pixelWidth / 8, pixelWidth / 4));
//Task first1 = Task.Factory.StartNew(() => generateGraphData(data, pixelWidth / 4, pixelWidth / 2));
//Task second1 = Task.Factory.StartNew(() => generateGraphData(data, pixelWidth / 2, pixelWidth));
//Task.WaitAll(first, second,first1,second1);
//duration.Content = string.Format("Duration (ms):{0}", watch.ElapsedMilliseconds);
//graphBitmap.WritePixels(new Int32Rect(0, 0, graphBitmap.PixelWidth, graphBitmap.PixelHeight), data, stride, 0);
//graphImage.Source = graphBitmap;
#endregion
}
示例8: DecodeJpeg
public static WriteableBitmap DecodeJpeg(Stream srcStream)
{
// Decode JPEG
var decoder = new FluxJpeg.Core.Decoder.JpegDecoder(srcStream);
var jpegDecoded = decoder.Decode();
var img = jpegDecoded.Image;
img.ChangeColorSpace(ColorSpace.RGB);
// Init Buffer
int w = img.Width;
int h = img.Height;
var result = new WriteableBitmap(w, h);
int[] p = result.Pixels;
byte[][,] pixelsFromJpeg = img.Raster;
// Copy FluxJpeg buffer into WriteableBitmap
int i = 0;
for (int x = 0; x < w; x++)
{
for (int y = 0; y < h; y++)
{
p[i++] = (0xFF << 24) // A
| (pixelsFromJpeg[0][x, y] << 16) // R
| (pixelsFromJpeg[1][x, y] << 8) // G
| pixelsFromJpeg[2][x, y]; // B
}
}
return result;
}
示例9: Update
public void Update(ImageFrameReadyEventArgs e)
{
if (depthFrame32 == null)
{
depthFrame32 = new byte[e.ImageFrame.Image.Width * e.ImageFrame.Image.Height * 4];
}
ConvertDepthFrame(e.ImageFrame.Image.Bits);
if (DepthBitmap == null)
{
DepthBitmap = new WriteableBitmap(e.ImageFrame.Image.Width, e.ImageFrame.Image.Height, 96, 96, PixelFormats.Bgra32, null);
}
DepthBitmap.Lock();
int stride = DepthBitmap.PixelWidth * DepthBitmap.Format.BitsPerPixel / 8;
Int32Rect dirtyRect = new Int32Rect(0, 0, DepthBitmap.PixelWidth, DepthBitmap.PixelHeight);
DepthBitmap.WritePixels(dirtyRect, depthFrame32, stride, 0);
DepthBitmap.AddDirtyRect(dirtyRect);
DepthBitmap.Unlock();
RaisePropertyChanged(()=>DepthBitmap);
}
示例10: 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();
}
}
示例11: GeneratePicture
async void GeneratePicture()
{
if (rendering) return;
ProgressIndicator prog = new ProgressIndicator();
prog.IsIndeterminate = true;
prog.Text = "Rendering";
prog.IsVisible = true;
SystemTray.SetProgressIndicator(this, prog);
var bmp = new WriteableBitmap(480, 800);
try
{
rendering = true;
using (var renderer = new WriteableBitmapRenderer(manager, bmp, OutputOption.PreserveAspectRatio))
{
display.Source = await renderer.RenderAsync();
}
SystemTray.SetProgressIndicator(this, null);
rendering = false;
}
finally
{
}
}
示例12: UpdateTiledImage
void UpdateTiledImage() {
if(sourceBitmap == null)
return;
var width = (int)Math.Ceiling(ActualWidth);
var height = (int)Math.Ceiling(ActualHeight);
// only regenerate the image if the width/height has grown
if(width < lastWidth && height < lastHeight)
return;
lastWidth = width;
lastHeight = height;
var final = new WriteableBitmap(width, height);
for(var x = 0; x < final.PixelWidth; x++) {
for(var y = 0; y < final.PixelHeight; y++) {
var tiledX = (x % sourceBitmap.PixelWidth);
var tiledY = (y % sourceBitmap.PixelHeight);
final.Pixels[y * final.PixelWidth + x] = sourceBitmap.Pixels[tiledY * sourceBitmap.PixelWidth + tiledX];
}
}
tiledImage.Source = final;
}
示例13: RecordedVideoFrame
public RecordedVideoFrame(ColorImageFrame colorFrame)
{
if (colorFrame != null)
{
byte[] bits = new byte[colorFrame.PixelDataLength];
colorFrame.CopyPixelDataTo(bits);
int BytesPerPixel = colorFrame.BytesPerPixel;
int Width = colorFrame.Width;
int Height = colorFrame.Height;
var bmp = new WriteableBitmap(Width, Height, 96, 96, PixelFormats.Bgr32, null);
bmp.WritePixels(new System.Windows.Int32Rect(0, 0, Width, Height), bits, Width * BytesPerPixel, 0);
JpegBitmapEncoder jpeg = new JpegBitmapEncoder();
jpeg.Frames.Add(BitmapFrame.Create(bmp));
var SaveStream = new MemoryStream();
jpeg.Save(SaveStream);
SaveStream.Flush();
JpegData = SaveStream.ToArray();
}
else
{
return;
}
}
示例14: GetPngStream
Stream GetPngStream(WriteableBitmap bmp)
{
// Use Joe Stegman's PNG Encoder
// http://bit.ly/77mDsv
EditableImage imageData = new EditableImage(bmp.PixelWidth, bmp.PixelHeight);
for (int y = 0; y < bmp.PixelHeight; ++y)
{
for (int x = 0; x < bmp.PixelWidth; ++x)
{
int pixel = bmp.Pixels[bmp.PixelWidth * y + x];
imageData.SetPixel(x, y,
(byte)((pixel >> 16) & 0xFF),
(byte)((pixel >> 8) & 0xFF),
(byte)(pixel & 0xFF),
(byte)((pixel >> 24) & 0xFF)
);
}
}
return imageData.GetStream();
}
示例15: GetRequestStreamCallback
void GetRequestStreamCallback(IAsyncResult callbackResult)
{
HttpWebRequest myRequest = (HttpWebRequest)callbackResult.AsyncState;
// End the stream request operation
Stream postStream = myRequest.EndGetRequestStream(callbackResult);
var settings = IsolatedStorageSettings.ApplicationSettings;
String token ="";
if (settings.Contains("tokken"))
{
token = settings["tokken"].ToString();
}
// Create the post data
string postData = "tokken=" + token + "&attrId=30";
MemoryStream ms = new MemoryStream();
WriteableBitmap btmMap = new WriteableBitmap(photo.PixelWidth,photo.PixelHeight);
// write an image into the stream
Extensions.SaveJpeg(btmMap, ms,
photo.PixelWidth, photo.PixelHeight, 0, 100);
//this.WriteEntry(postStream, "image",ms.ToArray());
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// Add the post data to the web request
postStream.Write(byteArray, 0, byteArray.Length);
postStream.Close();
// Start the web request
myRequest.BeginGetResponse(new AsyncCallback(GetResponsetStreamCallback), myRequest);
}