本文整理汇总了C#中System.Windows.Media.Imaging.RenderTargetBitmap.CopyPixels方法的典型用法代码示例。如果您正苦于以下问题:C# RenderTargetBitmap.CopyPixels方法的具体用法?C# RenderTargetBitmap.CopyPixels怎么用?C# RenderTargetBitmap.CopyPixels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.Imaging.RenderTargetBitmap
的用法示例。
在下文中一共展示了RenderTargetBitmap.CopyPixels方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAverageColor
public Color GetAverageColor(Visual visual, Rect area)
{
var bitmap = new RenderTargetBitmap(1, 1, 96, 96, PixelFormats.Pbgra32);
bitmap.Render(
new Rectangle
{
Width = 1,
Height = 1,
Fill = new VisualBrush { Visual = visual, Viewbox = area }
});
var bytes = new byte[4];
bitmap.CopyPixels(bytes, 1, 0);
return Color.FromArgb(bytes[0], bytes[1], bytes[2], bytes[3]);
}
示例2: AddFrame
private void AddFrame(AnimatedGifEncoder encoder)
{
var rtb = new RenderTargetBitmap((int)this.ActualWidth, (int)this.ActualHeight, 96, 96, PixelFormats.Pbgra32);
rtb.Render(this);
var bitmap = new WriteableBitmap((int)this.ActualWidth, (int)this.ActualHeight, 96, 96, PixelFormats.Pbgra32, null);
bitmap.FillRectangle(0, 0, bitmap.PixelWidth, bitmap.PixelWidth, Colors.Wheat);
bitmap.Lock();
rtb.CopyPixels(
new Int32Rect(0, 0, rtb.PixelWidth, rtb.PixelHeight),
bitmap.BackBuffer,
bitmap.BackBufferStride * bitmap.PixelHeight, bitmap.BackBufferStride);
bitmap.AddDirtyRect(new Int32Rect(0, 0, (int)ActualWidth, (int)ActualHeight));
bitmap.Unlock();
encoder.AddFrame(bitmap);
}
示例3: Paint
public override void Paint(PaintEventArgs args)
{
if (this.m_Sheet == null) return;
RenderTargetBitmap botmap = new RenderTargetBitmap(this.m_Sheet.Width, this.m_Sheet.Height, 96d, 96d, PixelFormats.Default);
if (this.m_Sheet.DocumentPage == null && this.m_Sheet.DocumentPageWrapper != null)
this.m_Sheet.DocumentPage = this.m_Sheet.DocumentPageWrapper.XPSDocumentPage;
if (this.m_Sheet.DocumentPage == null) return;
botmap.Render(this.m_Sheet.DocumentPage.Visual);
byte[] rgbValues = new byte[this.m_Sheet.Height * this.m_Sheet.Width * 4];
botmap.CopyPixels(rgbValues, this.m_Sheet.Width * 4, 0);
using (Bitmap bmp = new Bitmap(this.m_Sheet.Width, this.m_Sheet.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb)) {
System.Drawing.Imaging.BitmapData bd = bmp.LockBits(new Rectangle(0, 0, this.m_Sheet.Width, this.m_Sheet.Height),
System.Drawing.Imaging.ImageLockMode.WriteOnly,
System.Drawing.Imaging.PixelFormat.Format32bppRgb);
System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, bd.Scan0, rgbValues.Length);
bmp.UnlockBits(bd);
using (Synchronizer.Lock(this.SlideDisplay.SyncRoot)) {
Graphics g = args.Graphics;
///Lock the graphics object so it doesn't get used elsewhere.
using (Synchronizer.Lock(g)) {
g.Transform = this.SlideDisplay.PixelTransform;
using (Synchronizer.Lock(this.m_Sheet.SyncRoot)) {
using (Synchronizer.Lock(bmp)) {
g.DrawImage(bmp, this.m_Sheet.Bounds.X - 3, this.m_Sheet.Bounds.Y - 3, this.m_Sheet.Bounds.Width, this.m_Sheet.Bounds.Height);
}
}
}
}
}
System.GC.Collect();
}
示例4: saveImageFrame
private void saveImageFrame()
{
// SHOW A MESSAGE TO THE USER
// For memory testing when not using kinect
WriteableBitmap currentFrameCopy;
if (this.colorBitmap == null)
{
currentFrameCopy = new WriteableBitmap((int)kiddieHolder.ActualWidth, (int)kiddieHolder.ActualHeight, 96, 96, PixelFormats.Pbgra32, null);
currentFrameCopy.Lock();
RenderTargetBitmap rendrBMP = new RenderTargetBitmap((int)kiddieHolder.ActualWidth, (int)kiddieHolder.ActualHeight, 96, 96, PixelFormats.Pbgra32);
rendrBMP.Render(kiddieHolder);
rendrBMP.CopyPixels(new Int32Rect(0, 0, (int)kiddieHolder.ActualWidth, (int)kiddieHolder.ActualHeight), currentFrameCopy.BackBuffer, currentFrameCopy.BackBufferStride * currentFrameCopy.PixelHeight, currentFrameCopy.BackBufferStride);
currentFrameCopy.Unlock();
}
else
{
currentFrameCopy = this.colorBitmap.Clone();
}
currentFrameCopy.Freeze();
_photoSubmitter.encodeAndSubmitUserPhotoToCMS(currentFrameCopy);
}
开发者ID:guozanhua,项目名称:MFDetroit2013_Kinect_GreenScreen_PhotoKiosk,代码行数:24,代码来源:SectionPhotoOriginal.cs
示例5: RenderBitmapAndCapturePixels
private ImageSource RenderBitmapAndCapturePixels(MediaPlayer mediaPlayer, uint[] pixels)
{
// Render the current frame into a bitmap
var drawingVisual = new DrawingVisual();
var renderTargetBitmap = new RenderTargetBitmap(mediaPlayer.NaturalVideoWidth, mediaPlayer.NaturalVideoHeight, 96, 96, PixelFormats.Default);
using (var drawingContext = drawingVisual.RenderOpen())
{
drawingContext.DrawVideo(mediaPlayer, new Rect(0, 0, mediaPlayer.NaturalVideoWidth, mediaPlayer.NaturalVideoHeight));
}
renderTargetBitmap.Render(drawingVisual);
// Copy the pixels to the specified location
renderTargetBitmap.CopyPixels(pixels, mediaPlayer.NaturalVideoWidth * 4, 0);
// Return the bitmap
return renderTargetBitmap;
}
示例6: UpdateWallWeight
/// <summary>壁重み用の画像を作成する</summary>
private void UpdateWallWeight()
{
// 窓がある部分の周囲をぼかして塗りつぶした画像を作成
DrawingVisual blurVisual = new DrawingVisual();
blurVisual.Effect = _blurEffect;
using (DrawingContext dc = blurVisual.RenderOpen())
{
// 一旦塗りつぶし
dc.DrawRectangle(_aroundWinFGBrush, null, new Rect(-_screenRect.Width / 2.0, -_screenRect.Height / 2.0, _screenRect.Width * 2, _screenRect.Height * 2));
// スクリーンの境界部分のぼかしを作る
dc.DrawRectangle(_aroundWinBGBrush, null, new Rect(_blurEffect.Radius / 2.0, _blurEffect.Radius / 2.0, _screenRect.Width - _blurEffect.Radius, _screenRect.Height - _blurEffect.Radius));
// 各窓の領域を塗りつぶし
foreach (WindowInfo info in _wkgWindows)
{
if (info.IsMaximized) break;
if (info.IsMinimized) continue;
dc.DrawRectangle(_aroundWinFGBrush, null,
new Rect(info.Rect.X - _screenRect.X - _blurEffect.Radius / 2.0,
info.Rect.Y - _screenRect.Y - _blurEffect.Radius / 2.0,
info.Rect.Width + _blurEffect.Radius, info.Rect.Height + _blurEffect.Radius));
}
}
blurVisual.Clip = new RectangleGeometry(new Rect(0, 0, _screenRect.Width, _screenRect.Height));
// 窓内部を塗りつぶした画像を作成
DrawingVisual noblurVisual = new DrawingVisual();
using (DrawingContext dc = noblurVisual.RenderOpen())
{
dc.DrawRectangle(_innerWinBGBrush, null, new Rect(0, 0, _screenRect.Width, _screenRect.Height));
foreach (WindowInfo info in _wkgWindows)
{
if (info.IsMaximized) break;
if (info.IsMinimized) continue;
dc.DrawRectangle(_innerWinFGBrush, null,
new Rect(info.Rect.X, info.Rect.Y, info.Rect.Width, info.Rect.Height));
}
}
noblurVisual.Clip = new RectangleGeometry(new Rect(0, 0, _screenRect.Width, _screenRect.Height));
// 2枚の画像を重畳
DrawingVisual _wkgDrawingVisual = new DrawingVisual();
VisualBrush vb1 = new VisualBrush(blurVisual);
VisualBrush vb2 = new VisualBrush(noblurVisual);
Effect.ColorMergeEffect ef = new Effect.ColorMergeEffect();
ef.Key = (double)Effect.ColorMergeEffect.ColorKey.Green;
ef.Input2 = vb2;
_wkgDrawingVisual.Effect = ef;
using (DrawingContext dc = _wkgDrawingVisual.RenderOpen())
{
dc.DrawRectangle(vb1, null, new Rect(0, 0, _screenRect.Width, _screenRect.Height));
}
// 画像から壁重みの配列に変換
_rBmp = new RenderTargetBitmap((int)_screenRect.Width, (int)_screenRect.Height,
Common.Constants.DPIX, Common.Constants.DPIY, PixelFormats.Pbgra32);
_rBmp.Render(_wkgDrawingVisual);
_rBmp.Freeze();
_rBmp.CopyPixels(_wallPixels, (_rBmp.PixelWidth * _rBmp.Format.BitsPerPixel + 7) / 8, 0);
}
示例7: BrushTransform
internal BrushTransform(Brush brush, Rect bounds) {
ToAbsolute = Matrix.Identity;
ToAbsolute.Scale(bounds.Width, bounds.Height);
ToAbsolute.Translate(bounds.X, bounds.Y);
var fromAbsolute = ToAbsolute;
fromAbsolute.Invert();
ToBrush = fromAbsolute * brush.RelativeTransform.Value * ToAbsolute * brush.Transform.Value;
if (!ToBrush.HasInverse) {
var dv = new DrawingVisual();
using (var dc = dv.RenderOpen()) dc.DrawRectangle(brush, null, new Rect(0, 0, 1, 1));
var rtb = new RenderTargetBitmap(1, 1, 0, 0, PixelFormats.Pbgra32);
rtb.Render(dv);
var c = new byte[4];
rtb.CopyPixels(c, 4, 0);
DegenerateBrush = new d.SolidBrush(d.Color.FromArgb(c[3], c[2], c[1], c[0]));
}
}
示例8: 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="pngFilePath">
/// The png file path.
/// </param>
/// <returns>
/// The <see cref="BitmapSource"/>.
/// </returns>
public static BitmapSource PrintToPngFile(
Canvas canvas1, Canvas canvas2, Canvas canvas3, Canvas canvas4, string pngFilePath)
{
var rtb1 = new RenderTargetBitmap(
(int)Math.Round(canvas1.ActualWidth, 0),
(int)Math.Round(canvas1.ActualHeight, 0),
96.0,
96.0,
PixelFormats.Pbgra32);
ModifyPosition(canvas1);
rtb1.Render(canvas1);
ModifyPositionBack(canvas1);
var pixels1 = new byte[rtb1.PixelWidth * rtb1.PixelHeight * rtb1.Format.BitsPerPixel / 8];
rtb1.CopyPixels(pixels1, (rtb1.PixelWidth * rtb1.Format.BitsPerPixel) / 8, 0);
var rtb2 = new RenderTargetBitmap(
(int)Math.Round(canvas2.ActualWidth, 0),
(int)Math.Round(canvas2.ActualHeight, 0),
96.0,
96.0,
PixelFormats.Pbgra32);
ModifyPosition(canvas2);
rtb2.Render(canvas2);
ModifyPositionBack(canvas2);
var pixels2 = new byte[rtb2.PixelWidth * rtb2.PixelHeight * rtb2.Format.BitsPerPixel / 8];
rtb2.CopyPixels(pixels2, (rtb2.PixelWidth * rtb2.Format.BitsPerPixel) / 8, 0);
var rtb3 = new RenderTargetBitmap(
(int)Math.Round(canvas3.ActualWidth, 0),
(int)Math.Round(canvas3.ActualHeight, 0),
96.0,
96.0,
PixelFormats.Pbgra32);
ModifyPosition(canvas3);
rtb3.Render(canvas3);
ModifyPositionBack(canvas3);
var pixels3 = new byte[rtb3.PixelWidth * rtb3.PixelHeight * rtb3.Format.BitsPerPixel / 8];
rtb3.CopyPixels(pixels3, (rtb3.PixelWidth * rtb3.Format.BitsPerPixel) / 8, 0);
var rtb4 = new RenderTargetBitmap(
(int)Math.Round(canvas4.ActualWidth, 0),
(int)Math.Round(canvas4.ActualHeight, 0),
96.0,
96.0,
PixelFormats.Pbgra32);
ModifyPosition(canvas4);
rtb4.Render(canvas4);
ModifyPositionBack(canvas4);
var pixels4 = new byte[rtb4.PixelWidth * rtb4.PixelHeight * rtb4.Format.BitsPerPixel / 8];
rtb4.CopyPixels(pixels4, (rtb4.PixelWidth * rtb4.Format.BitsPerPixel) / 8, 0);
var wb = new WriteableBitmap(
rtb1.PixelWidth + rtb2.PixelWidth,
rtb1.PixelHeight + rtb3.PixelHeight,
96.0,
96.0,
PixelFormats.Pbgra32,
null);
wb.WritePixels(
new Int32Rect(0, 0, rtb1.PixelWidth, rtb1.PixelHeight),
pixels1,
(rtb1.PixelWidth * rtb1.Format.BitsPerPixel) / 8,
0);
wb.WritePixels(
new Int32Rect(rtb1.PixelWidth, 0, rtb2.PixelWidth, rtb2.PixelHeight),
pixels2,
(rtb2.PixelWidth * rtb2.Format.BitsPerPixel) / 8,
0);
wb.WritePixels(
new Int32Rect(0, rtb1.PixelHeight, rtb3.PixelWidth, rtb3.PixelHeight),
pixels3,
(rtb3.PixelWidth * rtb3.Format.BitsPerPixel) / 8,
0);
wb.WritePixels(
new Int32Rect(rtb3.PixelWidth, rtb2.PixelHeight, rtb4.PixelWidth, rtb4.PixelHeight),
//.........这里部分代码省略.........
示例9: PrintToPrinter
/// <summary>
/// The print to printer.
/// </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>
/// <returns>
/// The <see cref="BitmapSource"/>.
/// </returns>
public static BitmapSource PrintToPrinter(Canvas canvas1, Canvas canvas2, Canvas canvas3, Canvas canvas4)
{
var rtb1 = new RenderTargetBitmap(
(int)Math.Round(canvas1.ActualWidth, 0),
(int)Math.Round(canvas1.ActualHeight, 0),
96.0,
96.0,
PixelFormats.Pbgra32);
ModifyPosition(canvas1);
rtb1.Render(canvas1);
ModifyPositionBack(canvas1);
var pixels1 = new byte[rtb1.PixelWidth * rtb1.PixelHeight * rtb1.Format.BitsPerPixel / 8];
rtb1.CopyPixels(pixels1, (rtb1.PixelWidth * rtb1.Format.BitsPerPixel) / 8, 0);
var rtb2 = new RenderTargetBitmap(
(int)Math.Round(canvas2.ActualWidth, 0),
(int)Math.Round(canvas2.ActualHeight, 0),
96.0,
96.0,
PixelFormats.Pbgra32);
ModifyPosition(canvas2);
rtb2.Render(canvas2);
ModifyPositionBack(canvas2);
var pixels2 = new byte[rtb2.PixelWidth * rtb2.PixelHeight * rtb2.Format.BitsPerPixel / 8];
rtb2.CopyPixels(pixels2, (rtb2.PixelWidth * rtb2.Format.BitsPerPixel) / 8, 0);
var rtb3 = new RenderTargetBitmap(
(int)Math.Round(canvas3.ActualWidth, 0),
(int)Math.Round(canvas3.ActualHeight, 0),
96.0,
96.0,
PixelFormats.Pbgra32);
ModifyPosition(canvas3);
rtb3.Render(canvas3);
ModifyPositionBack(canvas3);
var pixels3 = new byte[rtb3.PixelWidth * rtb3.PixelHeight * rtb3.Format.BitsPerPixel / 8];
rtb3.CopyPixels(pixels3, (rtb3.PixelWidth * rtb3.Format.BitsPerPixel) / 8, 0);
var rtb4 = new RenderTargetBitmap(
(int)Math.Round(canvas4.ActualWidth, 0),
(int)Math.Round(canvas4.ActualHeight, 0),
96.0,
96.0,
PixelFormats.Pbgra32);
ModifyPosition(canvas4);
rtb4.Render(canvas4);
ModifyPositionBack(canvas4);
var pixels4 = new byte[rtb4.PixelWidth * rtb4.PixelHeight * rtb4.Format.BitsPerPixel / 8];
rtb4.CopyPixels(pixels4, (rtb4.PixelWidth * rtb4.Format.BitsPerPixel) / 8, 0);
var wb = new WriteableBitmap(
rtb1.PixelWidth + rtb2.PixelWidth,
rtb1.PixelHeight + rtb3.PixelHeight,
96.0,
96.0,
PixelFormats.Pbgra32,
null);
wb.WritePixels(
new Int32Rect(0, 0, rtb1.PixelWidth, rtb1.PixelHeight),
pixels1,
(rtb1.PixelWidth * rtb1.Format.BitsPerPixel) / 8,
0);
wb.WritePixels(
new Int32Rect(rtb1.PixelWidth, 0, rtb2.PixelWidth, rtb2.PixelHeight),
pixels2,
(rtb2.PixelWidth * rtb2.Format.BitsPerPixel) / 8,
0);
wb.WritePixels(
new Int32Rect(0, rtb1.PixelHeight, rtb3.PixelWidth, rtb3.PixelHeight),
pixels3,
(rtb3.PixelWidth * rtb3.Format.BitsPerPixel) / 8,
0);
wb.WritePixels(
new Int32Rect(rtb3.PixelWidth, rtb2.PixelHeight, rtb4.PixelWidth, rtb4.PixelHeight),
pixels4,
(rtb4.PixelWidth * rtb4.Format.BitsPerPixel) / 8,
0);
//.........这里部分代码省略.........
示例10: DrawLines
//.........这里部分代码省略.........
var angle = Math.Asin(Math.Abs(rect.Top - lastRect.Value.Top) / proportion) * (180 / Math.PI);
if (rect.Left > lastRect.Value.Left && rect.Top == lastRect.Value.Top)
{
angle += 90;
}
if (rect.Left < lastRect.Value.Left && rect.Top == lastRect.Value.Top)
{
angle -= 90;
}
if (rect.Left == lastRect.Value.Left && rect.Top > lastRect.Value.Top)
{
angle += 90;
}
if (rect.Left == lastRect.Value.Left && rect.Top < lastRect.Value.Top)
{
angle -= 90;
}
if (rect.Left > lastRect.Value.Left && rect.Top > lastRect.Value.Top)
{
angle += 90;
}
if (rect.Left > lastRect.Value.Left && rect.Top < lastRect.Value.Top)
{
angle = Math.Asin(Math.Abs(rect.Left - lastRect.Value.Left) / proportion) * (180 / Math.PI);
}
if (rect.Left < lastRect.Value.Left && rect.Top < lastRect.Value.Top)
{
angle -= 90;
}
if (rect.Left < lastRect.Value.Left && rect.Top > lastRect.Value.Top)
{
angle = Math.Asin(Math.Abs(rect.Left - lastRect.Value.Left) / proportion) * (180 / Math.PI);
angle -= 180;
}
var canvas = new Canvas();
var line = new Line
{
Stroke = new SolidColorBrush(color),
StrokeThickness = LineSize.Value * (scaleX + scaleY) / 2,
StrokeStartLineCap = PenLineCap.Round,
StrokeEndLineCap = PenLineCap.Round,
};
line.X1 = rect.Width / 2;
line.Y1 = rect.Height / 2;
line.X2 = rect.Width / 2;
line.Y2 = rect.Height / 2 + lineLength;
canvas.Children.Add(line);
canvas.RenderTransformOrigin = new Point(0.5, 0.5);
var transformGroup = new TransformGroup();
transformGroup.Children.Add(new RotateTransform(angle));
transformGroup.Children.Add(new TranslateTransform(rect.Left, rect.Top));
canvas.RenderTransform = transformGroup;
canvas.Measure(new Size(rect.Width, rect.Height));
canvas.Arrange(new Rect(new Size(rect.Width, rect.Height)));
canvas.UpdateLayout();
bitmap.Render(canvas);
}
}
lastRect = rect;
}
bitmap.CopyPixels(
result,
(int)(LayoutRoot.ActualWidth * scaleX) * 4,
0);
for (var offset = 0; offset < result.Length; offset += 4)
{
if (result[offset + 3] == 0) continue;
result[offset] = (byte)Math.Round(result[offset] / (result[offset + 3] / 255.0));
result[offset + 1] = (byte)Math.Round(result[offset + 1] / (result[offset + 3] / 255.0));
result[offset + 2] = (byte)Math.Round(result[offset + 2] / (result[offset + 3] / 255.0));
}
for (var offset = 0; offset < result.Length; offset += 4)
{
if (result[offset + 3] == 0) continue;
result[offset + 3] = Math.Min((byte)(result[offset + 3] * (LineColor.SelectedColor.Value.A / 255.0)), (byte)255);
}
return
BitmapSource.Create(
(int)(LayoutRoot.ActualWidth * scaleX),
(int)(LayoutRoot.ActualHeight * scaleY),
96, 96, PixelFormats.Bgra32, null, result, (int)(LayoutRoot.ActualWidth * scaleX) * 4);
}
示例11: ThreadFunc
private static void ThreadFunc(object state)
{
while (true)
{
var request = imageQueue.Take();
int width = request.Width;
int height = request.Heigth;
Image image = new Image { Width = width, Height = height, Source = request.DrawingImage, Stretch = Stretch.Fill };
image.Measure(new Size(width, height));
image.Arrange(new Rect(0, 0, width, height));
image.Dispatcher.Invoke(new Action(() => { }), DispatcherPriority.Background);
#if false
Window window = new Window();
window.Content = image;
window.Show();
#endif
RenderTargetBitmap renderBitmap = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);
renderBitmap.Render(image);
image.Dispatcher.Invoke(new Action(() => { }), DispatcherPriority.Background);
int[] pixels = new int[width * height];
renderBitmap.CopyPixels(pixels, (width * PixelFormats.Pbgra32.BitsPerPixel + 7) / 8, 0);
resultQueue.Add(pixels);
}
}
示例12: VisualToBitmap
public static BitmapSource VisualToBitmap(Visual e, int Width, int Height, GrayscaleParameters parameters)
{
Contract.Requires(e != null);
e.VerifyAccess();
RenderTargetBitmap src = new RenderTargetBitmap(Width, Height, 96, 96, PixelFormats.Pbgra32);
src.Render(e);
if (parameters != null)
{
byte[] pixels = new byte[Width * Height * 4];
src.CopyPixels(pixels, (Width * 4), 0);
for (int p = 0; p < pixels.Length; p += 4)
{
// compute grayscale
double pixelvalue =
(((double)pixels[p + 0] * parameters.RedDistribution) +
((double)pixels[p + 1] * parameters.GreenDistribution) +
((double)pixels[p + 2] * parameters.BlueDistribution));
// compute compression
pixelvalue = (pixelvalue * parameters.Compression) + (256 * ((1 - parameters.Compression) / 2));
// compute washout
pixelvalue = Math.Min(256, pixelvalue + (256 * parameters.Washout));
byte v = (byte)pixelvalue;
pixels[p + 0] = v;
pixels[p + 1] = v;
pixels[p + 2] = v;
}
return BitmapSource.Create(Width, Height, 96, 96, PixelFormats.Bgr32, null, pixels, Width * 4);
}
else
{
return src;
}
}
示例13: saveImageFrame
public void saveImageFrame()
{
// For memory testing when not using kinect
WriteableBitmap currentFrameCopy;
currentFrameCopy = new WriteableBitmap((int)kiddieHolder.ActualWidth, (int)kiddieHolder.ActualHeight, 96, 96, PixelFormats.Pbgra32, null);
currentFrameCopy.Lock();
RenderTargetBitmap rendrBMP = new RenderTargetBitmap((int)kiddieHolder.ActualWidth, (int)kiddieHolder.ActualHeight, 96, 96, PixelFormats.Pbgra32);
rendrBMP.Render(kiddieHolder);
rendrBMP.CopyPixels(new Int32Rect(0, 0, (int)kiddieHolder.ActualWidth, (int)kiddieHolder.ActualHeight), currentFrameCopy.BackBuffer, currentFrameCopy.BackBufferStride * currentFrameCopy.PixelHeight, currentFrameCopy.BackBufferStride);
currentFrameCopy.Unlock();
currentFrameCopy.Freeze();
_photoSubmitter.encodeAndSubmitUserPhotoToCMS(currentFrameCopy);
// Wierd WPF bug maybe messes up the visual brush. We can fix it just by doing this
if (blurMaskVisualBrush != null)
{
blurMaskVisualBrush.Visual = null;
blurMaskVisualBrush.Visual = _blurMaskSource;
}
}
开发者ID:guozanhua,项目名称:MFDetroit2013_Kinect_GreenScreen_PhotoKiosk,代码行数:23,代码来源:GreenScreenView.xaml.cs
示例14: Convert
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is FrameworkElement)
{
FrameworkElement e = (FrameworkElement)value;
if (e.ActualHeight == 0 || e.ActualWidth == 0) return null;
RenderTargetBitmap src = new RenderTargetBitmap((int)e.ActualWidth, (int)e.ActualHeight, 96, 96, PixelFormats.Pbgra32);
src.Render(e);
if (ConvertToGrayscale)
{
byte[] pixels = new byte[(int)src.Width * (int)src.Height * 4];
src.CopyPixels(pixels, ((int)src.Width * 4), 0);
for (int p = 0; p < pixels.Length; p += 4)
{
double val = (((double)pixels[p + 0] * _RedDistribution) + ((double)pixels[p + 1] * _GreenDistribution) + ((double)pixels[p + 2] * _BlueDistribution));
val = (val * Compression) + (256 * ((1 - Compression) / 2));
byte v = (byte)val;
pixels[p + 0] = v;
pixels[p + 1] = v;
pixels[p + 2] = v;
}
return BitmapSource.Create((int)src.Width, (int)src.Height, 96, 96, PixelFormats.Bgr32, null, pixels, (int)src.Width * 4);
}
else
{
return src;
}
}
return null;
}
示例15: SetImage
/// <summary>
/// Calculates thumbnail.
/// TODO: make stable fix bugs rehaul code **save planet** #$^*(*di76arm 7665764bomb8888111~~~!!! msg 78&*%*% over563345
/// </summary>
/// <param name="visual"></param>
/// <param name="dpi"></param>
public void SetImage(Visual visual, Size dpi)
{
Rect bounds = VisualTreeHelper.GetDescendantBounds(visual);
int w = (int)(bounds.Width * dpi.Width / 96.0);
int h = (int)(bounds.Height * dpi.Height / 96.0);
RenderTargetBitmap rtb = new RenderTargetBitmap(w, h
,
dpi.Width,
dpi.Height,
PixelFormats.Pbgra32);
DrawingVisual dv = new DrawingVisual();
using (DrawingContext ctx = dv.RenderOpen())
{
VisualBrush vb = new VisualBrush(visual);
ctx.DrawRectangle(vb, null, new Rect(new Point(), bounds.Size));
}
rtb.Render(dv);
_ThumbnailData = new byte[120 * 90 * 4];
byte[] temp = new byte[w * h * 4];
rtb.CopyPixels(temp, w * 4, 0);
MemoryStream ms = new MemoryStream();
BitmapImage bi = new BitmapImage();
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(rtb));
encoder.Save(ms);
ms.Seek(0, SeekOrigin.Begin);
byte[] result = new byte[ms.Length];
BinaryReader br = new BinaryReader(ms);
br.Read(result, 0, (int)ms.Length);
br.Close();
ms.Close();
bi.BeginInit();
//bi.DecodePixelHeight = 90;
bi.DecodePixelWidth = 120;
bi.StreamSource = new MemoryStream(result);
bi.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
bi.CacheOption = BitmapCacheOption.Default;
bi.EndInit();
bi.CopyPixels(this._ThumbnailData, 120 * 4, 0);
this._Thumbnail = rtb;
}