本文整理汇总了C#中System.Windows.Media.Imaging.RenderTargetBitmap.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# RenderTargetBitmap.Clone方法的具体用法?C# RenderTargetBitmap.Clone怎么用?C# RenderTargetBitmap.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.Imaging.RenderTargetBitmap
的用法示例。
在下文中一共展示了RenderTargetBitmap.Clone方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: export
/// <summary>
/// Image export method
/// Encodes a RenderTargetBitmap as a graphic-file (bmp, gif, jpeg, png or tiff) and saves it with the given filename.
/// </summary>
/// <param name="filename">Filename</param>
/// <returns>bool if the export was successfully</returns>
/// <author>Thomas Meents, Bernhard Bruns, Andrej Albrecht</author>
public bool export(String filename)
{
try
{
processModelCanvas.Background = Brushes.White;
RenderTargetBitmap render = new RenderTargetBitmap((int)processModelCanvas.Width, (int)processModelCanvas.Height, 96d, 96d, PixelFormats.Pbgra32);
render.Clone();
processModelCanvas.Measure(new Size((int)processModelCanvas.Width, (int)processModelCanvas.Height));
processModelCanvas.Arrange(new Rect(new Size((int)processModelCanvas.Width, (int)processModelCanvas.Height)));
render.Render(processModelCanvas);
switch (this.filetype)
{
case ".bmp":
BmpBitmapEncoder bmpEncoder = new BmpBitmapEncoder();
bmpEncoder.Frames.Add(BitmapFrame.Create(render));
using (FileStream bmpFile = File.Create(filename))
{
bmpEncoder.Save(bmpFile);
}
break;
case ".gif":
GifBitmapEncoder gifEncoder = new GifBitmapEncoder();
gifEncoder.Frames.Add(BitmapFrame.Create(render));
using (FileStream gifFile = File.Create(filename))
{
gifEncoder.Save(gifFile);
}
break;
case ".jpeg":
JpegBitmapEncoder jpegEncoder = new JpegBitmapEncoder();
jpegEncoder.Frames.Add(BitmapFrame.Create(render));
using (FileStream jpegFile = File.Create(filename))
{
jpegEncoder.Save(jpegFile);
}
break;
case ".png":
PngBitmapEncoder pngEncoder = new PngBitmapEncoder();
pngEncoder.Frames.Add(BitmapFrame.Create(render));
using (FileStream pngFile = File.Create(filename))
{
pngEncoder.Save(pngFile);
}
break;
case ".tiff":
TiffBitmapEncoder tiffEncoder = new TiffBitmapEncoder();
tiffEncoder.Frames.Add(BitmapFrame.Create(render));
using (FileStream tiffFile = File.Create(filename))
{
tiffEncoder.Save(tiffFile);
}
break;
}
return true;
}
catch (Exception)
{
return false;
}
}
示例2: TakeASnapshot
private void TakeASnapshot()
{
this.Dispatcher.Invoke(new Action(() =>
{
try
{
sv_MainCanvas.UpdateLayout();
drawingCanvas.UpdateLayout();
canvasesContainer.UpdateLayout();
double dpi = 96;
//prepare to render the notes
RenderTargetBitmap noteContainerRenderTargetBitmap = new RenderTargetBitmap((int)canvasesContainer.ActualWidth, (int)canvasesContainer.ActualHeight, dpi, dpi, PixelFormats.Pbgra32);
noteContainerRenderTargetBitmap.Render(canvasesContainer);
ImageSource NoteContainerImgSrc = (ImageSource)noteContainerRenderTargetBitmap.Clone();
BitmapFrame resizedNoteContainerBmpFrame = Utilities.UtilitiesLib.CreateResizedBitmapFrame(NoteContainerImgSrc, (int)(canvasesContainer.ActualWidth * 3 / 4), (int)(canvasesContainer.Height * 3 / 4), 0);
PngBitmapEncoder imageEncoder = new PngBitmapEncoder();
imageEncoder.Frames.Add(BitmapFrame.Create(resizedNoteContainerBmpFrame));
//imageEncoder.Frames.Add(BitmapFrame.Create(renderTargetBitmap));
byte[] screenshotBytes = new byte[1];
using (MemoryStream stream = new MemoryStream())
{
imageEncoder.Save(stream);
stream.Seek(0, 0);
screenshotBytes = stream.ToArray();
Utilities.GlobalObjects.currentScreenshotBytes = screenshotBytes;
//broadcastScreenshot(screenshotBytes);
Task.Factory.StartNew(() =>
{
BoardScreenUpdater.GetInstance(dropboxGeneralNoteDownloader.Storage).UpdateMetaplanBoardScreen(new MemoryStream(screenshotBytes));
});
//bgUploader.RunWorkerAsync(new MemoryStream(screenshotBytes));
}
}
catch (Exception ex)
{
Utilities.UtilitiesLib.LogError(ex);
}
}));
}