本文整理汇总了C#中System.Windows.Media.Imaging.WriteableBitmap类的典型用法代码示例。如果您正苦于以下问题:C# WriteableBitmap类的具体用法?C# WriteableBitmap怎么用?C# WriteableBitmap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WriteableBitmap类属于System.Windows.Media.Imaging命名空间,在下文中一共展示了WriteableBitmap类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:halllo,项目名称:DailyQuote,代码行数:29,代码来源:LockScreenImage.cs
示例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));
}
}
开发者ID:Core2D,项目名称:Core2D,代码行数:26,代码来源:SkiaView.cs
示例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();
}
}
}
开发者ID:danclarke,项目名称:WP7LiveTileDemo,代码行数:29,代码来源:TileUtil.cs
示例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);
}
开发者ID:LoveDuckie,项目名称:MerjTek.WpfIntegration,代码行数:13,代码来源:RenderTargetImageSource.cs
示例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 ();
}
开发者ID:dfr0,项目名称:moon,代码行数:7,代码来源:CaptureImageCompletedEventArgs.cs
示例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;
}
开发者ID:TrashTonyLin,项目名称:Two-Kinect-Measurement,代码行数:33,代码来源:ColorExtensions.cs
示例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
}
开发者ID:red201432,项目名称:CSharpLearn,代码行数:28,代码来源:MainWindow.xaml.cs
示例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;
}
开发者ID:Vinna,项目名称:DeepInSummer,代码行数:30,代码来源:JpegHelper.cs
示例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);
}
开发者ID:klosejiang,项目名称:Magic-Hands,代码行数:25,代码来源:DepthStreamManager.cs
示例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();
}
}
开发者ID:Expensify,项目名称:WindowsPhoneTestFramework,代码行数:26,代码来源:TakePictureCommand.cs
示例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
{
}
}
开发者ID:Nokia-Developer-Community-Projects,项目名称:wp8-sample,代码行数:35,代码来源:MainPage.xaml.cs
示例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;
}
开发者ID:CrazyBBer,项目名称:Caliburn.Micro.Learn,代码行数:25,代码来源:TiledBackground.cs
示例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;
}
}
开发者ID:pi11e,项目名称:KinectHTML5,代码行数:25,代码来源:RecordedVideoFrame.cs
示例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();
}
开发者ID:EdmilsonFernandes,项目名称:edm-azuli-condominio,代码行数:25,代码来源:MainPage.xaml.cs
示例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);
}
开发者ID:marcin-owoc,项目名称:TouristGuide,代码行数:31,代码来源:CapturingPhoto.xaml.cs
示例16: btnSalvar_Click
private void btnSalvar_Click(object sender, RoutedEventArgs e)
{
try
{
string _tmpImage = "tmpImage";
string _msgMensagem = "Imagem grava com sucesso!";
var store = IsolatedStorageFile.GetUserStoreForApplication();
if (store.FileExists(_tmpImage)) store.DeleteFile(_tmpImage);
IsolatedStorageFileStream _stream = store.CreateFile(_tmpImage);
WriteableBitmap _writeImage = new WriteableBitmap(_imagetmp);
Extensions.SaveJpeg(_writeImage, _stream, _writeImage.PixelWidth,
_writeImage.PixelHeight, 0, 100);
_stream.Close();
_stream = store.OpenFile(_tmpImage, System.IO.FileMode.Open,
System.IO.FileAccess.Read);
MediaLibrary _mlibrary = new MediaLibrary();
_mlibrary.SavePicture(_stream.Name, _stream);
_stream.Close();
btnSalvar.IsEnabled = false;
lblStatus.Text = _msgMensagem;
}
catch (Exception error)
{
lblStatus.Text = error.Message;
}
}
开发者ID:lhlima,项目名称:CollaborationProjects,代码行数:31,代码来源:MainPage.xaml.cs
示例17: WebClientOpenReadCompleted
void WebClientOpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
const string tempJpeg = "TempJPEG";
var streamResourceInfo = new StreamResourceInfo(e.Result, null);
var userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication();
if (userStoreForApplication.FileExists(tempJpeg))
{
userStoreForApplication.DeleteFile(tempJpeg);
}
var isolatedStorageFileStream = userStoreForApplication.CreateFile(tempJpeg);
var bitmapImage = new BitmapImage { CreateOptions = BitmapCreateOptions.None };
bitmapImage.SetSource(streamResourceInfo.Stream);
var writeableBitmap = new WriteableBitmap(bitmapImage);
writeableBitmap.SaveJpeg(isolatedStorageFileStream, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, 0, 85);
isolatedStorageFileStream.Close();
isolatedStorageFileStream = userStoreForApplication.OpenFile(tempJpeg, FileMode.Open, FileAccess.Read);
// Save the image to the camera roll or saved pictures album.
var mediaLibrary = new MediaLibrary();
// Save the image to the saved pictures album.
mediaLibrary.SavePicture(string.Format("SavedPicture{0}.jpg", DateTime.Now), isolatedStorageFileStream);
isolatedStorageFileStream.Close();
}
开发者ID:trilok567,项目名称:Windows-Phone,代码行数:30,代码来源:Page1.xaml.cs
示例18: FrameData
public FrameData( WriteableBitmap depth, WriteableBitmap color, double lat, double lng )
{
depthBitmap = depth;
colorBitmap = color;
latitude = lat;
longitude = lng;
}
开发者ID:nmilkosky,项目名称:StreetRecorder,代码行数:7,代码来源:FrameData.cs
示例19: myChooser_KinectChanged
void myChooser_KinectChanged(object sender, KinectChangedEventArgs e)
{
if (null != e.OldSensor)
{
//Alten Kinect deaktivieren
if (mySensor != null)
{
mySensor.Dispose();
}
}
if (null != e.NewSensor)
{
mySensor = e.NewSensor;
mySensor.AudioSource.Start();
mySensor.AudioSource.BeamAngleChanged += new EventHandler<BeamAngleChangedEventArgs>(AudioSource_BeamAngleChanged);
mySensor.AudioSource.SoundSourceAngleChanged += new EventHandler<SoundSourceAngleChangedEventArgs>(AudioSource_SoundSourceAngleChanged);
myBitmap = new WriteableBitmap(640,480, 96.0, 96.0, PixelFormats.Pbgra32, null);
image1.Source = myBitmap;
try
{
this.mySensor.Start();
SensorChooserUI.Visibility = Visibility.Hidden;
}
catch (IOException)
{
this.mySensor = null;
}
}
}
开发者ID:kinectNao,项目名称:bluenao,代码行数:30,代码来源:MainWindow.xaml.cs
示例20: TestWriteableBitmap
/// <summary>
/// WriteableBitmap -> IplImage
/// </summary>
private void TestWriteableBitmap()
{
// Load 16-bit image to WriteableBitmap
PngBitmapDecoder decoder = new PngBitmapDecoder(
new Uri(FilePath.Image.Depth16Bit, UriKind.Relative),
BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default
);
BitmapSource bs = decoder.Frames[0];
WriteableBitmap wb = new WriteableBitmap(bs);
// Convert wb into IplImage
IplImage ipl = wb.ToIplImage();
//IplImage ipl32 = new IplImage(wb.PixelWidth, wb.PixelHeight, BitDepth.U16, 1);
//WriteableBitmapConverter.ToIplImage(wb, ipl32);
// Print pixel values
for (int i = 0; i < ipl.Height; i++)
{
Console.WriteLine("x:{0} y:{1} v:{2}", i, i, ipl[i, 128]);
}
// Show 16-bit IplImage
using (new CvWindow("from WriteableBitmap to IplImage", ipl))
{
Cv.WaitKey();
}
}
开发者ID:0sv,项目名称:opencvsharp,代码行数:30,代码来源:ConvertToIplImage.cs
注:本文中的System.Windows.Media.Imaging.WriteableBitmap类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论