本文整理汇总了C#中System.Windows.Int32Rect类的典型用法代码示例。如果您正苦于以下问题:C# Int32Rect类的具体用法?C# Int32Rect怎么用?C# Int32Rect使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Int32Rect类属于System.Windows命名空间,在下文中一共展示了Int32Rect类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Window_Loaded
private void Window_Loaded( object sender, RoutedEventArgs e )
{
try {
kinect = KinectSensor.GetDefault();
if ( kinect == null ) {
throw new Exception("Kinectを開けません");
}
kinect.Open();
// 表示のためのデータを作成
depthFrameDesc = kinect.DepthFrameSource.FrameDescription;
// 表示のためのビットマップに必要なものを作成
depthImage = new WriteableBitmap( depthFrameDesc.Width, depthFrameDesc.Height,
96, 96, PixelFormats.Gray16, null );
depthBuffer = new ushort[depthFrameDesc.LengthInPixels];
depthRect = new Int32Rect( 0, 0, depthFrameDesc.Width, depthFrameDesc.Height );
depthStride = (int)(depthFrameDesc.Width * depthFrameDesc.BytesPerPixel);
ImageDepth.Source = depthImage;
// 初期の位置表示座標
depthPoint = new Point( depthFrameDesc.Width / 2, depthFrameDesc.Height / 2 );
// Depthリーダーを開く
depthFrameReader = kinect.DepthFrameSource.OpenReader();
depthFrameReader.FrameArrived += depthFrameReader_FrameArrived;
}
catch ( Exception ex ) {
MessageBox.Show( ex.Message );
Close();
}
}
示例2: MainWindow
/// <summary>
/// Constructor.
/// </summary>
/// <remarks>
/// Created by default automatically.
/// </remarks>
public MainWindow()
{
InitializeComponent();
int width = (int)Math.Ceiling(Math.Sqrt(sn_range));
int height = width;
m_shuffledBuffer = new WriteableBitmap(width, height, 96, 96, PixelFormats.Cmyk32, null);
m_sortedBuffer = new WriteableBitmap(width, height, 96, 96, PixelFormats.Cmyk32, null);
m_rect = new Int32Rect(0, 0, m_sortedBuffer.PixelWidth, m_sortedBuffer.PixelHeight);
m_bpp = (m_sortedBuffer.Format.BitsPerPixel + 7) / 8;
m_stride = m_sortedBuffer.PixelWidth * m_bpp;
m_arraySize = m_stride * m_sortedBuffer.PixelHeight;
imgSorted.Source = m_sortedBuffer;
imgShuffled.Source = m_shuffledBuffer;
imgShuffled.Width = width;
imgShuffled.Height = height;
imgSorted.Width = width;
imgSorted.Height = height;
txtOutput.IsReadOnly = true;
}
示例3: CardPack
public CardPack()
{
_pack = new List<Card>();
Uri uri = new Uri("./Images/cards.png", UriKind.Relative);
source = new BitmapImage(uri);
_cardFronts = new List<CroppedBitmap>();
CardBack = new Image();
int w = source.PixelWidth / 13;
int h = source.PixelHeight/5;
for (int s = 0; s < 4; s++)
{
for (int v = 0; v < 13; v++)
{
int imageIndex = (s*13) + v;
int fx = imageIndex % 13;
int fy = imageIndex / 13;
Int32Rect sourceRect = new Int32Rect(fx * w, fy * h, w, h);
CroppedBitmap front = new CroppedBitmap(source, sourceRect);
sourceRect = new Int32Rect(2 * w, 4 * h, w, h);
CroppedBitmap back = new CroppedBitmap(source, sourceRect);
Image frontImage = new Image {Source = front};
Image backImage = new Image { Source = back };
Card card = new Card((CardSuit)s, (CardValue)v, frontImage, backImage);
_pack.Add(card);
}
}
}
示例4: Draw
public void Draw(List<Cell> alives)
{
int width = Cells.GetLength(0);
int height = Cells.GetLength(1);
// Reserve the back buffer for updates
WriteableBitmap bitmap = _bitmap;
bitmap.Lock();
// Clear to white
var rect = new Int32Rect(0, 0, width, height);
bitmap.WritePixels(rect, _whiteBitmap, bitmap.BackBufferStride, 0);
unsafe
{
// Get a pointer to the back buffer
int pBackBuffer = (int)bitmap.BackBuffer;
foreach (Cell cell in alives)
{
// Find the address of the pixel to draw
int p = pBackBuffer + (cell.Y * bitmap.BackBufferStride);
p += cell.X * 4;
*((int*)p) = 0;
}
}
// Specify the area of the bitmap that changed
bitmap.AddDirtyRect(new Int32Rect(0, 0, width, height));
// Release the back buffer and make it available for display
bitmap.Unlock();
}
示例5: Show
public void Show(Int32Rect rpRect)
{
var rMainWindowHandle = new WindowInteropHelper(App.Current.MainWindow).Handle;
if (r_HwndSource == null)
{
var rParam = new HwndSourceParameters(nameof(ScreenshotToolOverlayWindow))
{
Width = 0,
Height = 0,
PositionX = 0,
PositionY = 0,
WindowStyle = 0,
UsesPerPixelOpacity = true,
HwndSourceHook = WndProc,
ParentWindow = rMainWindowHandle,
};
r_HwndSource = new HwndSource(rParam) { SizeToContent = SizeToContent.Manual, RootVisual = this };
}
var rBrowserWindowHandle = ServiceManager.GetService<IBrowserService>().Handle;
NativeStructs.RECT rBrowserWindowRect;
NativeMethods.User32.GetWindowRect(rBrowserWindowHandle, out rBrowserWindowRect);
var rHorizontalRatio = rBrowserWindowRect.Width / GameConstants.GameWidth;
var rVerticalRatio = rBrowserWindowRect.Height / GameConstants.GameHeight;
rpRect.X = (int)(rpRect.X * rHorizontalRatio);
rpRect.Y = (int)(rpRect.Y * rVerticalRatio);
rpRect.Width = (int)(rpRect.Width * rHorizontalRatio);
rpRect.Height = (int)(rpRect.Height * rVerticalRatio);
NativeMethods.User32.SetWindowPos(r_HwndSource.Handle, IntPtr.Zero, rBrowserWindowRect.Left + rpRect.X, rBrowserWindowRect.Top + rpRect.Y, rpRect.Width, rpRect.Height, NativeEnums.SetWindowPosition.SWP_NOZORDER | NativeEnums.SetWindowPosition.SWP_NOACTIVATE | NativeEnums.SetWindowPosition.SWP_SHOWWINDOW);
}
示例6: 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;
}
示例7: MainWindow
public MainWindow()
{
InitializeComponent();
try
{
CompositionTarget.Rendering += CompositionTarget_Rendering;
//_kC.InitialCalibration();
this._colorImageBitmapRect = new Int32Rect(0, 0, 640, 480);
this._colorImageStride = 640 * 4;
this._colorImageBitmap1 = new WriteableBitmap(640, 480, 96, 96, PixelFormats.Bgr32, null);
this._colorImageBitmap2 = new WriteableBitmap(640, 480, 96, 96, PixelFormats.Bgr32, null);
this._colorImageBitmap3 = new WriteableBitmap(640, 480, 96, 96, PixelFormats.Bgr32, null);
this._colorImageBitmap4 = new WriteableBitmap(640, 480, 96, 96, PixelFormats.Bgr32, null);
this._colorImageBitmap5 = new WriteableBitmap(640, 480, 96, 96, PixelFormats.Bgr32, null);
this.ColorImageElement1.Source = this._colorImageBitmap1;
this.ColorImageElement2.Source = this._colorImageBitmap2;
this.ColorImageElement3.Source = this._colorImageBitmap3;
this.ColorImageElement4.Source = this._colorImageBitmap4;
this.ColorImageElement5.Source = this._colorImageBitmap5;
//this.ColorImageElement1.Source = kC.GetDifferenceBitmap();
//this.ColorImageElement3.Source = kC.GetPic2Bitmap();
}
catch (Exception e)
{
Console.Error.WriteLine(e.StackTrace);
}
}
示例8: Initialize
public void Initialize(KinectSensor sensor)
{
this.sensor = sensor;
coordinateMapper = new CoordinateMapper(sensor);
//Prepare for RGB image information receive
sensor.ColorStream.Enable(ColorImageFormat.RgbResolution1280x960Fps12);
imageSize = new Int32Rect(0, 0, sensor.ColorStream.FrameWidth, sensor.ColorStream.FrameHeight);
stride = imageSize.Width * 4; // blue, green, red, empty
colorData = new byte[sensor.ColorStream.FramePixelDataLength];
ColorBitmap = new WriteableBitmap(imageSize.Width, imageSize.Height, 96, 96, PixelFormats.Bgr32, null);
TransformSmoothParameters smooth = new TransformSmoothParameters()
{
Smoothing = Parameters.Kinect.Smoothing,
Correction = Parameters.Kinect.Correction,
Prediction = Parameters.Kinect.Prediction,
JitterRadius = Parameters.Kinect.JitterRadius,
MaxDeviationRadius = Parameters.Kinect.MaxDeviationRadius
};
sensor.SkeletonStream.TrackingMode = Parameters.Kinect.TrackingMode;
sensor.SkeletonStream.Enable(smooth);
sensor.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(sensor_SkeletonFrameReady);
sensor.ColorFrameReady += new EventHandler<ColorImageFrameReadyEventArgs>(sensor_ColorFrameReady);
sensor.Start();
Initialized = true;
}
示例9: CalculateLuminanceRGB
private void CalculateLuminanceRGB(BitmapSource bitmap)
{
var width = bitmap.PixelWidth;
var height = bitmap.PixelHeight;
var stepX = (bitmap.Format.BitsPerPixel + 7) / 8;
var bufferSize = width * stepX;
var buffer = new byte[bufferSize];
var rect = new Int32Rect(0, 0, width, 1);
var luminanceIndex = 0;
luminances = new byte[width * height];
for (var curY = 0; curY < height; curY++)
{
bitmap.CopyPixels(rect, buffer, bufferSize, 0);
for (var curX = 0; curX < bufferSize; curX += stepX)
{
var r = buffer[curX];
var g = buffer[curX + 1];
var b = buffer[curX + 2];
luminances[luminanceIndex] = (byte)
(0.3 * r + 0.59 * g + 0.11 * b + 0.01);
luminanceIndex++;
}
rect.Y++;
}
}
示例10: EncodeColorAsync
public async Task EncodeColorAsync(byte[] colorData, BinaryWriter writer)
{
if (this.Width == this.OutputWidth && this.Height == this.OutputHeight)
{
// Header
writer.Write(this.Width);
writer.Write(this.Height);
writer.Write(colorData.Length);
// Data
writer.Write(colorData);
}
else
{
WriteableBitmap bmp = BitmapFactory.New(this.Width, this.Height);
int stride = this.Width * 4; // 4 bytes per pixel in BGRA
var dirtyRect = new Int32Rect(0, 0, this.Width, this.Height);
bmp.WritePixels(dirtyRect, colorData, stride, 0);
var newBytes = await Task.FromResult(bmp.Resize(this.OutputWidth, this.OutputHeight, WriteableBitmapExtensions.Interpolation.NearestNeighbor).ToByteArray());
// Header
writer.Write(this.OutputWidth);
writer.Write(this.OutputHeight);
writer.Write(newBytes.Length);
writer.Write(newBytes);
}
}
示例11: AddFrame
public void AddFrame(string path, Int32Rect rect, int delay = 66)
{
//TODO: If global color is used, get all colors from all frames and write only 1 color table.
GeneratePalette(path);
CalculateColorTableSize();
if (IsFirstFrame)
{
FullSize = rect;
WriteLogicalScreenDescriptor(rect);
//Global color table.
if (UseGlobalColorTable)
WritePalette();
if (RepeatCount > -1)
WriteApplicationExtension();
}
WriteGraphicControlExtension(delay);
WriteImageDescriptor(rect);
//TODO: If it has Global color table, no need to use local.
//if uses global, all colors should be added to that palette.
//Local color table.
if (!UseGlobalColorTable)
WritePalette();
WriteImage();
IsFirstFrame = false;
}
示例12: KinectImage
//セットアップ
public KinectImage()
#region
{
//キネクト
this.kinect = KinectSensor.GetDefault();
//bodyIndexFrameの処理
this.bodyIndexFrameDes = this.kinect.BodyIndexFrameSource.FrameDescription;
this.bodyIndexFrameReader = this.kinect.BodyIndexFrameSource.OpenReader();
this.bodyIndexFrameReader.FrameArrived += this.BodyIndexFrame_Arrived;
//画像情報
this.kinectImgPackage = new ShadowPackage();
this.imageWidth = this.bodyIndexFrameDes.Width; // imgW;
this.imageHeight = this.bodyIndexFrameDes.Height; // imgH;
this.imageBytePerPixel = (int)this.bodyIndexFrameDes.BytesPerPixel;
this.bitmapRec = new Int32Rect(0, 0, this.imageWidth, this.imageHeight);
this.bitmapStride = (int)(this.imageWidth * this.imageBytePerPixel);
this.bodyIndexBuffer = new byte[this.imageWidth *
this.imageHeight * this.imageBytePerPixel];
this.kinectImage = new Mat(this.imageHeight, this.imageWidth, MatType.CV_8UC1);
//キネクト開始
this.kinect.Open();
}
示例13: GetPixelColor
public Color GetPixelColor(int x, int y) {
Color color;
var bytesPerPixel = (_screenSource.Format.BitsPerPixel + 7) / 8;
var bytes = new byte[bytesPerPixel];
var rect = new Int32Rect(x, y, 1, 1);
_screenSource.CopyPixels(rect, bytes, bytesPerPixel, 0);
if (_screenSource.Format == PixelFormats.Pbgra32) {
color = Color.FromArgb(bytes[3], bytes[2], bytes[1], bytes[0]);
} else if (_screenSource.Format == PixelFormats.Bgr32) {
color = Color.FromArgb(0xFF, bytes[2], bytes[1], bytes[0]);
} else if (_screenSource.Format == PixelFormats.Bgra32) {
color = Color.FromArgb(bytes[3], bytes[2], bytes[1], bytes[0]);
} else {
if (!_hasBeenWarned) {
Logging.Warning("Unsupported format: " + _screenSource.Format);
_hasBeenWarned = true;
}
color = Colors.Black;
}
return color;
}
示例14: RenderMaterial
public void RenderMaterial()
{
int width = (int)Width;
int height = (int)Height;
byte[] pixels = new byte[4 * height * width];
WriteableBitmap writeableBitmap = new WriteableBitmap(width, height, 96, 96, PixelFormats.Bgra32, null);
for (int p=0; p<width*height; p++)
{
Colour fillColour = _Material._DiffuseColour;
fillColour.Clamp(0, 1);
pixels[p*4] = (byte)(fillColour._Blue * 255.99f);
pixels[p*4+1] = (byte)(fillColour._Green * 255.99f);
pixels[p*4+2] = (byte)(fillColour._Red * 255.99f);
pixels[p*4+3] = 255;
}
Int32Rect rect = new Int32Rect(0, 0, width, height);
writeableBitmap.WritePixels(rect, pixels, width * 4, (int)0);
MaterialImage.Source = writeableBitmap;
}
示例15: CreateUVImage
private void CreateUVImage()
{
this.Bitmap.Lock();
var rect = new Int32Rect(0, 0, Bitmap.PixelWidth, Bitmap.PixelHeight);
var bytesPerPixel = (Bitmap.Format.BitsPerPixel + 7) / 8; // 1 ピクセル当たりのバイト数(4 になるはず)
var stride = Bitmap.PixelWidth * bytesPerPixel; // 幅方向のバイト数
var arraySize = stride * Bitmap.PixelHeight;
pixelEntity = new byte[arraySize];
int index; // 左上隅からのバイトのインデックス
for (int y = 0; y < Bitmap.PixelHeight; ++y)
{
for (int x = 0; x < Bitmap.PixelWidth; ++x)
{
index = x * bytesPerPixel + y * stride;
var r = (byte)(((double)x / Bitmap.PixelWidth) * 255);
var g = (byte)(((double)y / Bitmap.PixelHeight) * 255);
pixelEntity[index] = 0;
pixelEntity[index + 1] = g;
pixelEntity[index + 2] = r;
pixelEntity[index + 3] = 255;
}
}
Bitmap.WritePixels(rect, pixelEntity, stride, 0);
this.Bitmap.Unlock();
}