本文整理汇总了C#中System.Windows.Media.Imaging.RenderTargetBitmap类的典型用法代码示例。如果您正苦于以下问题:C# RenderTargetBitmap类的具体用法?C# RenderTargetBitmap怎么用?C# RenderTargetBitmap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RenderTargetBitmap类属于System.Windows.Media.Imaging命名空间,在下文中一共展示了RenderTargetBitmap类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CreateBitmap
public void CreateBitmap()
{
int width = 100;
int height = 100;
int dpi = 96;
Tracing.Log(">> CreateBitmap");
var thread = new Thread(new ThreadStart(() =>
{
Tracing.Log(">> CreateBitmap - Thread start; creating drawing visual");
//Dispatcher.Invoke(new Action(() => {
_drawingVisual = new DrawingVisual();
_drawingContext = _drawingVisual.RenderOpen();
//}));
Tracing.Log(">> CreateBitmap - Drawing to context");
_drawingContext.DrawRectangle(new SolidColorBrush(Colors.HotPink), new Pen(), new Rect(0, 0, 50, 50));
_drawingContext.DrawRectangle(new SolidColorBrush(Colors.Blue), new Pen(), new Rect(50, 0, 50, 50));
_drawingContext.DrawRectangle(new SolidColorBrush(Colors.Orange), new Pen(), new Rect(0, 50, 50, 50));
_drawingContext.DrawRectangle(new SolidColorBrush(Colors.DarkRed), new Pen(), new Rect(50, 50, 50, 50));
_drawingContext.Close();
Tracing.Log(">> CreateBitmap - Finished drawing; creating render target bitmap");
_bitmap = new RenderTargetBitmap(width, height, dpi, dpi, PixelFormats.Default);
_bitmap.Render(_drawingVisual);
Tracing.Log(">> CreateBitmap - Finished work");
_bitmap.Freeze();
}));
//thread.IsBackground = true;
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
开发者ID:pascalfr,项目名称:MPfm,代码行数:32,代码来源:TestControl.cs
示例2: Create3DViewPort
private void Create3DViewPort()
{
var hvp3d = new HelixViewport3D();
Viewport3D vp3d = new Viewport3D();
var lights = new DefaultLights();
var tp = new Teapot();
hvp3d.Children.Add(lights);
hvp3d.Children.Add(tp);
vp3d = hvp3d.Viewport;
tata.Children.Add(vp3d); // comenter ca pour test
/* MEGA TEST DE L'ESPACE SUBSAHARIEN */
RenderTargetBitmap bmp = new RenderTargetBitmap(800, 800, 96, 96, PixelFormats.Pbgra32);
var rect = new Rect(0, 0, 800, 800);
vp3d.Measure(new Size(800, 800));
vp3d.Arrange(rect);
vp3d.InvalidateVisual();
bmp.Render(vp3d);
PngBitmapEncoder png = new PngBitmapEncoder();
png.Frames.Add(BitmapFrame.Create(bmp));
String filepath = "C:\\Users\\Remi\\Desktop\\canardmasque.png";
using (Stream stm = File.Create(filepath))
{
png.Save(stm);
}
}
开发者ID:remi-hernandez,项目名称:renderHelixViewPort3d,代码行数:32,代码来源:MainWindow.xaml.cs
示例3: ButtonSave_Click
private void ButtonSave_Click(object sender, RoutedEventArgs e)
{
var rect = new Rect { Width = 512, Height = 384 };
var dv = new DrawingVisual();
var dc = dv.RenderOpen();
dc.PushTransform(new TranslateTransform(-rect.X, -rect.Y));
dc.DrawRectangle(InkCanvasMain.Background, null, rect);
InkCanvasMain.Strokes.Draw(dc);
dc.Close();
var rtb = new RenderTargetBitmap((int)rect.Width, (int)rect.Height, 96, 96, PixelFormats.Default);
rtb.Render(dv);
var enc = new PngBitmapEncoder();
enc.Frames.Add(BitmapFrame.Create(rtb));
var fn = TextBoxFileName.Text;
if (!fn.EndsWith(".png", StringComparison.OrdinalIgnoreCase)) fn += ".png";
using (Stream s = File.Create(TegakiImageFolder + "/" + fn))
{
enc.Save(s);
}
((TegakiWindowViewModel)DataContext).AddToMediaList(System.IO.Path.GetFullPath(TegakiImageFolder + "/" + fn));
Close();
}
开发者ID:kb10uy,项目名称:Kbtter4,代码行数:25,代码来源:TegakiWindow.xaml.cs
示例4: getFeatures
private double[] getFeatures()
{
rtb = new RenderTargetBitmap((int)InkCanvas1.ActualWidth, (int)InkCanvas1.ActualHeight,
96d, 96d, PixelFormats.Default);
rtb.Render(InkCanvas1);
//save the ink to a memory stream
BmpBitmapEncoder encoder = new BmpBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(rtb));
byte[] bitmapBytes;
Bitmap bmp;
using (MemoryStream ms = new MemoryStream())
{
encoder.Save(ms);
ms.Position = 0;
bitmapBytes = ms.ToArray();
ms.Seek(0, SeekOrigin.Begin);
bmp = new Bitmap(ms);
}
bmp = resize.Apply(bmp);
double[] features = ToFeatures(bmp);
return features;
}
开发者ID:CanerPatir,项目名称:framework,代码行数:29,代码来源:DrawingCanvas.xaml.cs
示例5: CreateCursor
public static Cursor CreateCursor(UIElement element, int xHotSpot,
int yHotSpot)
{
element.Measure(new Size(double.PositiveInfinity,
double.PositiveInfinity));
element.Arrange(new Rect(0, 0, element.DesiredSize.Width,
element.DesiredSize.Height));
RenderTargetBitmap rtb =
new RenderTargetBitmap((int)element.DesiredSize.Width,
(int)element.DesiredSize.Height, 96, 96, PixelFormats.Pbgra32);
rtb.Render(element);
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(rtb));
MemoryStream ms = new MemoryStream();
encoder.Save(ms);
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);
ms.Close();
ms.Dispose();
Cursor cur = InternalCreateCursor(bmp, xHotSpot, yHotSpot);
bmp.Dispose();
return cur;
}
开发者ID:heinzsack,项目名称:DEV,代码行数:30,代码来源:CursorHelper.cs
示例6: Convert
public void Convert(IEnumerable<IAssetImageSource> sources, string target, VisualAssetInfo visualAsset)
{
if (sources == null)
{
throw new ArgumentNullException("sources");
}
if (string.IsNullOrEmpty(target))
{
throw new ArgumentNullException("target");
}
if (visualAsset == null)
{
throw new ArgumentNullException("visualAsset");
}
var rectangle = this.GetRectangleBounds(visualAsset.Width, visualAsset.Height, visualAsset.Margin);
var drawingVisual = this.CreateDrawingVisual(sources, rectangle);
var targetBitmap = new RenderTargetBitmap(visualAsset.Width, visualAsset.Height, 96, 96, PixelFormats.Pbgra32);
targetBitmap.Render(drawingVisual);
var png = new PngBitmapEncoder();
png.Frames.Add(BitmapFrame.Create(targetBitmap));
using (var stream = new FileStream(target, FileMode.Create, FileAccess.Write))
{
png.Save(stream);
}
}
开发者ID:duracellko,项目名称:WindowsApp-VisualAssets,代码行数:29,代码来源:ImageAssetConverter.cs
示例7: Convert
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
// Converts a Canvas to an image source
var canvas = value as Canvas;
if (canvas == null)
{
return null;
}
var param = parameter as CanvasToImageSourceParameters;
double width = canvas.Width;
double height = canvas.Height;
if (param != null)
{
width = param.Width;
height = param.Height;
}
if (!canvas.IsMeasureValid)
{
canvas.Measure(new Size(width, height));
canvas.Arrange(new Rect(0, 0, width, height));
canvas.UpdateLayout();
}
var rtb = new RenderTargetBitmap((int)width, (int)height, 96d, 96d, PixelFormats.Pbgra32);
rtb.Render(canvas);
var bmp = GetBitmap(rtb);
return rtb;
}
开发者ID:dEMonaRE,项目名称:HearthstoneTracker,代码行数:29,代码来源:CanvasToImageSourceConverter.cs
示例8: DrawGraphicsOnBitmap
public DrawGraphicsOnBitmap()
{
Title = "Draw Graphics on Bitmap";
// ��Ʈ���� ������� �����ϱ� ���� ����� ������.
Background = Brushes.Khaki;
// RenderTargetBitmap ������.
RenderTargetBitmap renderbitmap = new RenderTargetBitmap(100, 100, 96, 96, PixelFormats.Default);
// DrawingVisual ��ü�� ������.
DrawingVisual drawvis = new DrawingVisual();
DrawingContext dc = drawvis.RenderOpen(); // Render �ҵ� ȣ��
dc.DrawRoundedRectangle(Brushes.Blue, new Pen(Brushes.Red, 10),
new Rect(25, 25, 50, 50), 10, 10);
dc.Close();
// RenderTargetBitmap ���� DrawingVisual ��ü�� ��.
renderbitmap.Render(drawvis);
// �̹��� ��ä ���� -> ������Ƽ ����
Image img = new Image();
img.Source = renderbitmap;
// ���
Content = img;
}
开发者ID:gawallsibya,项目名称:BIT_MFC-CShap-DotNet,代码行数:27,代码来源:DrawGraphicsOnBitmap.cs
示例9: XamlDrawingToPngBase64String
/// <summary>
/// Преобразует XAML Drawing/DrawingGroup в png base64 string
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="drawing"></param>
/// <returns>Base64 string containing png bitmap</returns>
public static string XamlDrawingToPngBase64String(int width, int height, Drawing drawing) {
var bitmapEncoder = new PngBitmapEncoder();
// The image parameters...
double dpiX = 96;
double dpiY = 96;
// The Visual to use as the source of the RenderTargetBitmap.
var drawingVisual = new DrawingVisual();
using (var drawingContext = drawingVisual.RenderOpen()) {
drawingContext.DrawDrawing(drawing);
}
var bounds = drawingVisual.ContentBounds;
var targetBitmap = new RenderTargetBitmap(
width * 10, height * 10, dpiX, dpiY,
PixelFormats.Pbgra32);
drawingVisual.Transform = new ScaleTransform(width * 10 / bounds.Width, height * 10 / bounds.Height);
targetBitmap.Render(drawingVisual);
// Encoding the RenderBitmapTarget as an image.
bitmapEncoder.Frames.Add(BitmapFrame.Create(targetBitmap));
byte[] values;
using (var str = new MemoryStream()) {
bitmapEncoder.Save(str);
values = str.ToArray();
}
return Convert.ToBase64String(values);
}
开发者ID:xbadcode,项目名称:Rubezh,代码行数:38,代码来源:InternalConverter.cs
示例10: CreatePdfDocument
public Document CreatePdfDocument(Chart chart, string path)
{
RenderTargetBitmap renderBitmap = new RenderTargetBitmap(
(int) chart.ActualWidth,
(int) chart.ActualHeight,
96d,
96d,
PixelFormats.Pbgra32);
renderBitmap.Render(chart);
MemoryStream stream = new MemoryStream();
BitmapEncoder encoder = new BmpBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
encoder.Save(stream);
Bitmap bitmap = new Bitmap(stream);
System.Drawing.Image image = bitmap;
System.Drawing.Image resizedImage = ResizeImage(image, image.Width*2, image.Height);
Document doc = new Document(PageSize.A4);
PdfWriter.GetInstance(doc, new FileStream(path, FileMode.OpenOrCreate));
doc.Open();
Image pdfImage = Image.GetInstance(resizedImage, ImageFormat.Jpeg);
doc.Add(pdfImage);
doc.Close();
return doc;
}
开发者ID:LexaGal,项目名称:Plants,代码行数:30,代码来源:PdfDocumentCreator.cs
示例11: OnUpdate
protected override void OnUpdate(double[] values)
{
const double space = 3;
const double barwidth = 8;
int pts = values.Length / 2;
int width = 1000;//pts * (space + barwidth) - space;
int height = width / 4;
if (_bmp == null || width != _bmp.PixelWidth)
{
_bmp = new RenderTargetBitmap(width, height, 120, 96, PixelFormats.Pbgra32);
}
DrawingVisual drawingVisual = new DrawingVisual();
DrawingContext drawingContext = drawingVisual.RenderOpen();
Brush brush = DrawingBrush.Clone();
brush.Freeze();
double totalWidth = width / pts;
double totalBarWidth = totalWidth * ((barwidth) / (barwidth + space));
double totalSpace = totalWidth * ((space) / (barwidth + space));
for (int i = 0; i < pts; i++)
{
double x = i * totalWidth;
double y1 = height;
double y2 = y1 - values[i] * height;
drawingContext.DrawRectangle(brush, null, new Rect(x, y2, totalBarWidth, y1));
}
drawingContext.Close();
_bmp.Clear();
_bmp.Render(drawingVisual);
PART_visualationDisplay.Source = _bmp;
}
开发者ID:CheViana,项目名称:AudioLab,代码行数:34,代码来源:PeakSpectrum.cs
示例12: GetNewMessagesNotificationOverlay
public static ImageSource GetNewMessagesNotificationOverlay(Window window, DataTemplate template, int count = 0)
{
if (window == null)
return null;
var presentation = PresentationSource.FromVisual(window);
if (presentation == null)
return null;
Matrix m = presentation.CompositionTarget.TransformToDevice;
double dx = m.M11;
double dy = m.M22;
double iconWidth = 16.0 * dx;
double iconHeight = 16.0 * dy;
string countText = count.ToString();
RenderTargetBitmap bmp = new RenderTargetBitmap((int) iconWidth, (int) iconHeight, 96, 96, PixelFormats.Default);
ContentControl root = new ContentControl
{
ContentTemplate = template,
Content = count > 99 ? "…" : countText
};
root.Arrange(new Rect(0, 0, iconWidth, iconHeight));
bmp.Render(root);
return bmp;
}
开发者ID:kveretennicov,项目名称:kato,代码行数:31,代码来源:Taskbarhelper.cs
示例13: ButtonBase_OnClick
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
var bitmap = new RenderTargetBitmap((int)Math.Ceiling(Grid.RenderSize.Width), (int)Math.Ceiling(Grid.RenderSize.Height), 96, 96, PixelFormats.Default);
bitmap.Render(Grid);
Grid.Effect = new CircleRevealTransitionEffect
{
OldImage = new ImageBrush(bitmap),
Reverse = !ToggleButton.IsChecked.Value
};
TaskbarItemInfo = ToggleButton.IsChecked == true
? new TaskbarItemInfo {ProgressState = TaskbarItemProgressState.Indeterminate}
: new TaskbarItemInfo {ProgressState = TaskbarItemProgressState.None};
Application.Current.Resources["Dunno"] = ToggleButton.IsChecked == true ? Application.Current.Resources["Dunno2"] : Application.Current.Resources["Dunno1"];
Grid.Background = ToggleButton.IsChecked == true ? Brushes.Transparent : _background;
OnAirImage.Visibility = ToggleButton.IsChecked == true ? Visibility.Visible : Visibility.Collapsed;
_compositeNodeViewModel.ResetNodes();
_sw = Stopwatch.StartNew();
_timer?.Stop();
_timer = new DispatcherTimer(TimeSpan.FromMilliseconds(10), DispatcherPriority.Normal, Callback, Dispatcher);
}
开发者ID:misupov,项目名称:Turbina,代码行数:26,代码来源:MainWindow.xaml.cs
示例14: ExportToPng
public static byte[] ExportToPng(this FrameworkElement surface)
{
var transform = surface.LayoutTransform;
surface.LayoutTransform = null;
var size = new Size(surface.ActualWidth, surface.ActualHeight);
surface.Measure(size);
surface.Arrange(new Rect(size));
var renderBitmap = new RenderTargetBitmap((int)size.Width, (int)size.Height, 96d, 96d, PixelFormats.Pbgra32);
renderBitmap.Render(surface);
try
{
using (var outStream = new MemoryStream())
{
var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
encoder.Save(outStream);
return outStream.ToArray();
}
}
finally
{
surface.LayoutTransform = transform;
}
}
开发者ID:PeletonSoft,项目名称:Sketch,代码行数:27,代码来源:ImageCaptureHelper.cs
示例15: GetJpgImage
///
/// Gets a JPG "screenshot" of the current UIElement
///
/// UIElement to screenshot
/// Scale to render the screenshot
/// JPG Quality
/// Byte array of JPG data
public byte[] GetJpgImage(double scale, int quality, int dpi)
{
double actualHeight = this.RootVisual.RenderSize.Height;
double actualWidth = this.RootVisual.RenderSize.Width;
double renderHeight = actualHeight * scale;
double renderWidth = actualWidth * scale;
RenderTargetBitmap renderTarget = new RenderTargetBitmap((int)renderWidth, (int)renderHeight, dpi, dpi, PixelFormats.Pbgra32);
VisualBrush sourceBrush = new VisualBrush(this.RootVisual);
DrawingVisual drawingVisual = new DrawingVisual();
DrawingContext drawingContext = drawingVisual.RenderOpen();
using (drawingContext)
{
drawingContext.PushTransform(new ScaleTransform(scale, scale));
drawingContext.DrawRectangle(sourceBrush, null, new Rect(new Point(0, 0), new Point(actualWidth, actualHeight)));
}
renderTarget.Render(drawingVisual);
JpegBitmapEncoder jpgEncoder = new JpegBitmapEncoder();
jpgEncoder.QualityLevel = quality;
jpgEncoder.Frames.Add(BitmapFrame.Create(renderTarget));
Byte[] _imageArray;
using (MemoryStream outputStream = new MemoryStream())
{
jpgEncoder.Save(outputStream);
_imageArray = outputStream.ToArray();
}
return _imageArray;
}
开发者ID:CadeLaRen,项目名称:digiCamControl,代码行数:41,代码来源:PhotoCard.cs
示例16: SaveToPng
public void SaveToPng( Canvas surface, string file )
{
// Save current canvas transform
var transform = surface.LayoutTransform;
// reset current transform (in case it is scaled or rotated)
surface.LayoutTransform = null;
var size = new Size( 1600, 900 );
// Attentation: Measure and arrange the surface !
surface.Measure( size );
surface.Arrange( new Rect( size ) );
var renderBitmap = new RenderTargetBitmap( (int)size.Width, (int)size.Height, 96d, 96d, PixelFormats.Pbgra32 );
var bounds = VisualTreeHelper.GetDescendantBounds( surface );
var dv = new DrawingVisual();
using ( var ctx = dv.RenderOpen() )
{
var vb = new VisualBrush( surface );
ctx.DrawRectangle( vb, null, new Rect( new Point(), bounds.Size ) );
}
renderBitmap.Render( dv );
using ( var outStream = new FileStream( file, FileMode.OpenOrCreate, FileAccess.Write ) )
{
var encoder = new PngBitmapEncoder();
encoder.Frames.Add( BitmapFrame.Create( renderBitmap ) );
encoder.Save( outStream );
}
// Restore previously saved layout
surface.LayoutTransform = transform;
}
开发者ID:JackWangCUMT,项目名称:Plainion.Whiteboard,代码行数:34,代码来源:PersistenceService.cs
示例17: RenderBrush
/// <summary>
/// Renders the brush.
/// </summary>
/// <param name="path">
/// The path.
/// </param>
/// <param name="brush">
/// The brush.
/// </param>
/// <param name="w">
/// The w.
/// </param>
/// <param name="h">
/// The h.
/// </param>
public static void RenderBrush(string path, Brush brush, int w, int h)
{
var ib = brush as ImageBrush;
if (ib != null)
{
var bi = ib.ImageSource as BitmapImage;
if (bi != null)
{
w = bi.PixelWidth;
h = bi.PixelHeight;
}
}
var bmp = new RenderTargetBitmap(w, h, 96, 96, PixelFormats.Pbgra32);
var rect = new Grid
{
Background = brush,
Width = 1,
Height = 1,
LayoutTransform = new ScaleTransform(w, h)
};
rect.Arrange(new Rect(0, 0, w, h));
bmp.Render(rect);
var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bmp));
using (Stream stm = File.Create(path))
{
encoder.Save(stm);
}
}
开发者ID:BEEden,项目名称:Diplomarbeit,代码行数:47,代码来源:Exporter.cs
示例18: RenderPages
/// <summary>
/// Generates an image of each page in the year book
/// and saves it to the src folder
/// </summary>
/// <param name="bv"></param>
/// <param name="folderloc"></param>
private static void RenderPages(BookViewer bv, string folderloc)
{
int currentpage = bv.ViewIndex;
//loops though each page
foreach (Page p in bv.CurrentBook.Pages)
{
bv.ViewIndex = p.PageNumber;
//forces the canvas to re-render
BookViewer.DesignerCanvas.UpdateLayout();
//takes a picture of the canvas
RenderTargetBitmap rtb = new RenderTargetBitmap(PaperSize.Pixel.PaperWidth, PaperSize.Pixel.PaperHeight, 96, 96, PixelFormats.Default);
rtb.Render(BookViewer.DesignerCanvas);
//getting the bleed margin
Int32Rect bleedmargin = new Int32Rect((PaperSize.Pixel.PaperWidth - PaperSize.Pixel.BleedWidth) / 2, (PaperSize.Pixel.PaperHeight - PaperSize.Pixel.BleedHeight) / 2, PaperSize.Pixel.BleedWidth, PaperSize.Pixel.BleedHeight);
//cropping the image
CroppedBitmap cb = new CroppedBitmap(rtb, bleedmargin);
//encodes the image in png format
PngBitmapEncoder pbe = new PngBitmapEncoder();
pbe.Frames.Add(BitmapFrame.Create(cb));
//saves the resulting image
FileStream fs = File.Open(folderloc + "\\src\\" + (p.PageNumber+1) + ".png", FileMode.Create);
pbe.Save(fs);
fs.Flush();
fs.Close();
}
bv.ViewIndex = currentpage;
}
开发者ID:rakuza,项目名称:YBM2012,代码行数:34,代码来源:WebPublisher.cs
示例19: GetImage
public static RenderTargetBitmap GetImage(UIElement fe, Brush background = null, Size sz = default(Size), int dpi = 144)
{
if (sz.Width < alib.Math.math.ε || sz.Height < alib.Math.math.ε)
{
fe.Measure(util.infinite_size);
sz = fe.DesiredSize; //VisualTreeHelper.GetContentBounds(fe).Size; //
}
DrawingVisual dv = new DrawingVisual();
RenderOptions.SetEdgeMode(dv, EdgeMode.Aliased);
using (DrawingContext ctx = dv.RenderOpen())
{
Rect r = new Rect(0, 0, sz.Width, sz.Height);
if (background != null)
ctx.DrawRectangle(background, null, r);
VisualBrush br = new VisualBrush(fe);
br.AutoLayoutContent = true;
ctx.DrawRectangle(br, null, r);
}
Double f = dpi / 96.0;
RenderTargetBitmap bitmap = new RenderTargetBitmap(
(int)(sz.Width * f) + 1,
(int)(sz.Height * f) + 1,
dpi,
dpi,
PixelFormats.Pbgra32);
bitmap.Render(dv);
return bitmap;
}
开发者ID:hehaotian,项目名称:igt-editor,代码行数:33,代码来源:misc.cs
示例20: GetJpgImage
/// <summary>
/// </summary>
/// <param name="source"> </param>
/// <param name="scale"> </param>
/// <param name="quality"> </param>
/// <returns> </returns>
public static byte[] GetJpgImage(UIElement source, double scale, int quality)
{
var actualHeight = source.RenderSize.Height;
var actualWidth = source.RenderSize.Width;
var renderHeight = actualHeight * scale;
var renderWidth = actualWidth * scale;
var renderTarget = new RenderTargetBitmap((int) renderWidth, (int) renderHeight, 96, 96, PixelFormats.Pbgra32);
var sourceBrush = new VisualBrush(source);
var drawingVisual = new DrawingVisual();
var drawingContext = drawingVisual.RenderOpen();
using (drawingContext)
{
drawingContext.PushTransform(new ScaleTransform(scale, scale));
drawingContext.DrawRectangle(sourceBrush, null, new Rect(new Point(0, 0), new Point(actualWidth, actualHeight)));
}
renderTarget.Render(drawingVisual);
var jpgEncoder = new JpegBitmapEncoder
{
QualityLevel = quality
};
jpgEncoder.Frames.Add(BitmapFrame.Create(renderTarget));
Byte[] imageArray;
using (var outputStream = new MemoryStream())
{
jpgEncoder.Save(outputStream);
imageArray = outputStream.ToArray();
}
return imageArray;
}
开发者ID:Yaguar666,项目名称:ffxivapp-common,代码行数:35,代码来源:ScreenCapture.cs
注:本文中的System.Windows.Media.Imaging.RenderTargetBitmap类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论