本文整理汇总了C#中System.Drawing.Rectangle.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# Rectangle.Equals方法的具体用法?C# Rectangle.Equals怎么用?C# Rectangle.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Rectangle
的用法示例。
在下文中一共展示了Rectangle.Equals方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
public void Update(Graphics g, string text, Font font, Padding internalBounds,
Rectangle bounds, Color color, TextFormatFlags formatFlags, IThemeTextOption[] options) {
IntPtr compatHdc = this._TextHDC;
if (bounds.Equals(_TextHDCBounds)) {
//Same bounds, reuse HDC and Clear it
IntPtr hClearBrush = Native.GDI.CreateSolidBrush(ColorTranslator.ToWin32(Color.Black));
Native.RECT cleanRect = new Native.RECT(bounds);
Native.GDI.FillRect(compatHdc, ref cleanRect, hClearBrush);
Native.GDI.DeleteObject(hClearBrush);
}
else {
//Other bounds, create new HDC
IntPtr outputHdc = g.GetHdc();
IntPtr DIB;
compatHdc = CreateNewHDC(outputHdc, bounds, out DIB);
//Store new data
_TextHDC = compatHdc;
_TextHDCBounds = bounds;
//Clear up
CleanUpHDC(DIB);
g.ReleaseHdc(outputHdc);
}
DrawOnHDC(compatHdc, text, font, internalBounds, bounds, color, formatFlags, options);
}
示例2: FindBoxSobel
/// <summary>
/// Returns a rectangle inside 'lookInside' that bounds any energy greater than 'threshold'.
/// </summary>
/// <param name="image"></param>
/// <param name="lookInside">A rectangle of 'image' to look inside. </param>
/// <param name="threshold">1-255, the energy threshold to detect activity. 80-150 is a good range.</param>
/// <returns></returns>
public Rectangle FindBoxSobel(Bitmap originalImage, Rectangle lookInside, byte threshold)
{
Bitmap image = originalImage;
try {
//Convert if needed (makes an extra copy)
if (image.PixelFormat != PixelFormat.Format24bppRgb &&
image.PixelFormat != PixelFormat.Format32bppArgb &&
image.PixelFormat != PixelFormat.Format32bppRgb) {
image = AForge.Imaging.Image.Clone(image, PixelFormat.Format24bppRgb);
}
//Crop if needed (makes an extra copy unless we converted too, then only 1 extra copy)
if (!lookInside.Equals(new Rectangle(0, 0, image.Width, image.Height))) {
Bitmap oldImage = image;
try {
image = new Crop(lookInside).Apply(image);
} finally {
if (oldImage != originalImage) oldImage.Dispose(); //Dispose the cloned
}
}
//Makes 1 more copy at 1/3rd the size, in grayscale
Rectangle result = FindBoxSobel(image, threshold);
return new Rectangle(lookInside.X + result.X, lookInside.Y + result.Y, result.Width, result.Height);
} finally {
if (image != originalImage) image.Dispose();
}
}
示例3: GetBrush
// ------------------------------------------------------------------
/// <summary>
/// Gets the brush.
/// </summary>
/// <param name="rectangle">The rectangle.</param>
/// <returns>Brush</returns>
// ------------------------------------------------------------------
public Brush GetBrush(Rectangle rectangle) {
if (rectangle.Equals(Rectangle.Empty)) {
return new SolidBrush(mStartColor);
} else {
if (rectangle.Width == 0) {
rectangle.Width = 1;
}
if (rectangle.Height == 0) {
rectangle.Height = 1;
}
return new LinearGradientBrush(
rectangle,
mStartColor,
mEndColor,
mAngle,
true);
}
}
示例4: Contains
public bool Contains(Rectangle other)
{
return other.Equals(GetIntersection(other));
}
示例5: ProcessArrowScrolling
void ProcessArrowScrolling(Rectangle arrowButton, ref bool arrowVisible, ref bool arrowPressed, ref bool timerTicking)
{
// Capture the mouse
Capture = true;
// Draw the arrow button pushed
timerTicking = true;
// Draw pushed button
buttonPushed = true;
DrawArrowButton(arrowButton, ButtonState.Pushed);
// Start timer
using (System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer())
{
timer.Tick += new EventHandler(ScrollingTick);
timer.Interval = 300;
timer.Start();
doScrollingLoop = true;
while (doScrollingLoop)
{
// Check messages until we find a condition to break out of the loop
Win32.MSG msg = new Win32.MSG();
WindowsAPI.GetMessage(ref msg, 0, 0, 0);
Point point = new Point(0, 0);
if (msg.message == (int)Msg.WM_MOUSEMOVE || msg.message == (int)Msg.WM_LBUTTONUP)
{
point = WindowsAPI.GetPointFromLPARAM((int)msg.lParam);
}
switch (msg.message)
{
case (int)Msg.WM_MOUSEMOVE:
{
if (arrowButton.Contains(point))
{
if (!buttonPushed)
{
DrawArrowButton(arrowButton, ButtonState.Pushed);
arrowVisible = true;
arrowPressed = true;
buttonPushed = true;
}
}
else
{
if (buttonPushed)
{
DrawArrowButton(arrowButton, ButtonState.Normal);
arrowVisible = false;
arrowPressed = false;
buttonPushed = false;
}
}
break;
}
case (int)Msg.WM_LBUTTONUP:
{
if (buttonPushed)
{
if (!flatArrowButtons)
{
// Only if using regular buttons
DrawArrowButton(arrowButton, ButtonState.Normal);
}
buttonPushed = false;
}
arrowVisible = false;
if (arrowButton.Contains(point))
{
if (arrowButton.Equals(upArrowRect))
{
if (firstItem > 0)
{
firstItem--;
Rectangle rc = GetViewPortRect();
Invalidate(rc);
}
}
else if (arrowButton.Equals(downArrowRect))
{
using (Graphics g = Graphics.FromHwnd(Handle))
{
// Get the last item rectangle
OutlookBarBand band = bands[currentBandIndex];
if (band != null)
{
Rectangle rcItem = GetItemRect(g, band, band.Items.Count - 1, Rectangle.Empty);
Rectangle rc = GetViewPortRect();
if (rcItem.Bottom > rc.Bottom)
{
firstItem++;
Invalidate(rc);
}
}
}
}
}
doScrollingLoop = false;
break;
}
//.........这里部分代码省略.........
示例6: AddMarker
/// <summary>
/// Adds a marker with its configurations and image to layout manager.
/// </summary>
/// <param name="markerID">The ID of the marker (specified by the ARTag)</param>
/// <param name="upperLeftCorner">The upper left corner (in pixels) of this marker in the entire
/// marker array.</param>
/// <param name="size">The size of this marker to be printed on the marker array. If different
/// from the original image size, the marker image will be resized to fit this size.</param>
/// <param name="cropArea">The area to be retained after cropping other parts outside of
/// this area</param>
/// <param name="imagefile">The file name of the marker image (must have an extension that
/// indicates the image format)</param>
/// <param name="additionalInfos">Additional information that should be added to the config file</param>
/// <exception cref="ArgumentException">If the given marker ID is already added</exception>
/// <exception cref="InvalidOperationException"></exception>
public void AddMarker(int markerID, Point upperLeftCorner, Size size, Rectangle cropArea, String imagefile,
List<KeyValuePair<string, string>> additionalInfos)
{
if (configs.ContainsKey(markerID))
throw new ArgumentException("You can't add same marker ID in one config file");
MarkerConfig config = new MarkerConfig();
config.ID = markerID;
config.Position = upperLeftCorner;
int width = 0, height = 0;
config.Image = ImageReader.Load(imagefile, ref width, ref height);
config.ImageWidth = width;
config.ImageHeight = height;
config.CropArea = cropArea;
config.AdditionalInfo = additionalInfos;
config.ImageFilename = imagefile;
if (size.Equals(Size.Empty))
{
if (!cropArea.Equals(Rectangle.Empty))
config.Size = cropArea.Size;
else
config.Size = new Size(width, height);
}
else
config.Size = size;
// if crop area is not empty, then make sure that the crop area is within the marker size
if (!cropArea.Equals(Rectangle.Empty))
{
if (cropArea.X < 0 || cropArea.X > width)
throw new ArgumentException("Your crop area's X position is outside of the marker size");
if (cropArea.Y < 0 || cropArea.Y > height)
throw new ArgumentException("Your crop area's Y position is outside of the marker size");
if ((cropArea.X + cropArea.Width) > width)
throw new ArgumentException("Your crop area's X dimension exceeds the marker width");
if ((cropArea.Y + cropArea.Height) > height)
throw new ArgumentException("Your crop area's Y dimension exceeds the marker height");
}
configs.Add(markerID, config);
markerIDs.Add(markerID);
}
示例7: MatchTopLevelWindowForApplication
/// <summary>
/// Matches a top-level window to the application to the window having the specified dimensions.
/// </summary>
/// <param name="applicationName">The name of the application as registered with the AT-SPI registry.</param>
/// <param name="windowRect">A <see cref="System.Drawing.Rectangle"/> representing the window on the screen.</param>
/// <param name="frameExtents">A WindowManagerFrameExtents structure containing the size (in pixels) of the
/// decorations placed on the window by the window manager.</param>
/// <returns>A <see cref="System.IntPtr"/> value that points to the Accessible object representing the top-level window.</returns>
internal IntPtr MatchTopLevelWindowForApplication(string applicationName, Rectangle windowRect, WindowManagerFrameExtents frameExtents)
{
IntPtr windowPointer = IntPtr.Zero;
IList<IntPtr> topLevelWindows = this.GetTopLevelWindowsForApplication(applicationName);
foreach (IntPtr candidateWindow in topLevelWindows)
{
if (Accessible_isComponent(candidateWindow))
{
// Out variables for API call
int x = 0;
int y = 0;
int width = 0;
int height = 0;
int relativeX = 0;
int relativeY = 0;
IntPtr component = Accessible_getComponent(candidateWindow);
AccessibleComponent_getExtents(component, out x, out y, out width, out height, AccessibleCoordType.Screen);
AccessibleComponent_getPosition(component, out relativeX, out relativeY, AccessibleCoordType.Window);
AccessibleComponentLayer layer = AccessibleComponent_getLayer(component);
Rectangle componentRectangle = new Rectangle(x, y, width, height);
AccessibleComponent_unref(component);
// If the component layer is Window, this indicates that the window
// rect as passed in by the X server does not include the window frame
// as drawn by the window manager. If this is the case, adjust the rectangle
// so the window can be found.
if (layer == AccessibleComponentLayer.Window)
{
windowRect.X = windowRect.X - frameExtents.Left;
windowRect.Y = windowRect.Y - frameExtents.Top;
windowRect.Width = windowRect.Width + frameExtents.Left + frameExtents.Right;
windowRect.Height = windowRect.Height + frameExtents.Top + frameExtents.Bottom;
}
// If we found the window, add its pointer to the referenced objects
// cache and remove it from the list of available windows (so it
// does not get unreferenced.
if (windowRect.Equals(componentRectangle))
{
referencedObjectCache.Add(candidateWindow);
topLevelWindows.Remove(candidateWindow);
windowPointer = candidateWindow;
break;
}
}
}
// Unreference every window not matching as the top-level window
// for the application.
foreach (IntPtr referencedWindow in topLevelWindows)
{
Accessible_unref(referencedWindow);
}
return windowPointer;
}
示例8: CommonEditorUse
protected virtual void CommonEditorUse(Control ctl, Rectangle rectTarget) {
Debug.WriteLineIf(CompModSwitches.DebugGridView.TraceVerbose, "PropertyGridView:CommonEditorUse");
Debug.WriteLineIf(GridViewDebugPaint.TraceVerbose, "Showing common editors");
Debug.Assert(ctl != null, "Null control passed to CommonEditorUse");
Rectangle rectCur = ctl.Bounds;
// the client rect minus the border line
Rectangle clientRect = this.ClientRectangle;
clientRect.Inflate(-1,-1);
try {
rectTarget = Rectangle.Intersect(clientRect, rectTarget);
//if (ctl is Button)
// Debug.WriteStackTrace();
if (!rectTarget.IsEmpty) {
if (!rectTarget.Equals(rectCur)) {
ctl.SetBounds(rectTarget.X,rectTarget.Y,
rectTarget.Width,rectTarget.Height);
}
ctl.Visible = true;
}
}
catch {
rectTarget = Rectangle.Empty;
}
if (rectTarget.IsEmpty) {
ctl.Visible = false;
}
currentEditor = ctl;
}
示例9: CommonEditorUse
protected virtual void CommonEditorUse(Control ctl, Rectangle rectTarget)
{
Rectangle bounds = ctl.Bounds;
Rectangle clientRectangle = base.ClientRectangle;
clientRectangle.Inflate(-1, -1);
try
{
rectTarget = Rectangle.Intersect(clientRectangle, rectTarget);
if (!rectTarget.IsEmpty)
{
if (!rectTarget.Equals(bounds))
{
ctl.SetBounds(rectTarget.X, rectTarget.Y, rectTarget.Width, rectTarget.Height);
}
ctl.Visible = true;
}
}
catch
{
rectTarget = Rectangle.Empty;
}
if (rectTarget.IsEmpty)
{
ctl.Visible = false;
}
this.currentEditor = ctl;
}
示例10: SetBoundsCore
protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
{
bool skipMessage = false;
Rectangle newBounds = new Rectangle(x, y, width, height);
if (GUIGraphicsContext._useScreenSelector && isMaximized)
{
if (!newBounds.Equals(GUIGraphicsContext.currentScreen.Bounds))
{
skipMessage = true;
}
}
if (skipMessage)
{
Log.Info("d3dapp: Screenselector: skipped SetBoundsCore {0} does not match {1}", newBounds.ToString(),
GUIGraphicsContext.currentScreen.Bounds.ToString());
}
else
{
base.SetBoundsCore(x, y, width, height, specified);
}
}
示例11: GetAnswer
private RecognitionResult GetAnswer(Rectangle fragment)
{
foreach (var answer in sampleResults)
{
if (fragment.Equals(answer.Region))
{
return answer;
}
}
return null;
}
示例12: InsertRectangle
/// <summary>
/// Wstawia prostok�t do kontenera
/// </summary>
/// <param name="r">Prostok�t do wstawienia</param>
/// <param name="rLeftTop">Lewy g�rny wierzcho�ek prostok�ta</param>
/// <param name="o">Orientacja prostok�ta</param>
public void InsertRectangle(Rectangle r, Point rLeftTop, Rectangle.Orientation o)
{
Console.WriteLine("insert rect[(" + r.LeftTop.X + ", " + r.LeftTop.Y + "), (" +
r.RightDown.X + ", " + r.RightDown.Y + ")]" + " -> (" + rLeftTop.X + ", " +
rLeftTop.Y + ")");
InsertRectangleCheckParameters(r, rLeftTop);
if (o.Equals(Rectangle.Orientation.Horizontal) && r.SideA < r.SideB)
r.Rotate();
else if (o.Equals(Rectangle.Orientation.Vertical) && r.SideA > r.SideB)
r.Rotate();
if (rectangles.Count == 0)
FirstRectanglePreparation(r);
else
r.Move(rLeftTop);
rectangles.Add(r);
//jesli to byl pierwszy prostakat wszystko jest dobrze - nie trzeba tego robic
if (rectangles.Count > 1)
{
// spr. czy po dodaniu wciaz prawidlowy prostokat
if (isCorrectRectangle)
{
// doklejamy od dolu prostokata
if (r.LeftTop.X == maxCorrectRect.LeftTop.X &&
r.RightDown.X == maxCorrectRect.RightDown.X &&
r.LeftTop.Y <= maxCorrectRect.RightDown.Y)
UpdateMaxRectangles(r);
// doklejamy z prawej strony prostokata
else if (r.LeftTop.Y == maxCorrectRect.LeftTop.Y &&
r.RightDown.Y == maxCorrectRect.RightDown.Y &&
r.LeftTop.X <= maxCorrectRect.RightDown.X)
UpdateMaxRectangles(r);
// naklejamy na prostokat
else if (maxCorrectRect.Covers(r))
r.SetParentRectangle(maxCorrectRect);
// zaklejamy ca�y prostok�t - to r�wnie g�upi przypadek jak poprzedni, ale skoro kto� tak chce...
else if (r.Covers(maxCorrectRect))
UpdateMaxRectangles(r);
// calosc przestaje byc poprawnym prostokatem
else
{
isCorrectRectangle = false;
AddNewEmptyFields(r);
UpdateMaxPossibleRectangle(r);
}
}// gdy calosc nie jest prawidlowym prostokatem
else
{
//sprawdzenie czy dodanie prostokata nie pokrylo calkowicie jakichs emptyFields
//spr. czy przeciecia dodanego z empty sa niepuste (jesli tak - usuwamy odpow. empty z listy i wstawiamy zamiast niego empty-dodany)
//spr. czy nie zmienil sie maxPossibleRect
UpdateEmptyFields(r);
if (emptyFields.Count == 0)
UpdateMaxCorrectAfterFillingAllEmpties();
UpdateMaxPossibleRectangle(r);
}
}
}
示例13: BitmapBuffer
/// <summary>
/// Create a BitmapBuffer from a Bitmap, a Rectangle specifying what part from the Bitmap to take and a flag if we need a clone
/// </summary>
/// <param name="sourceBmp">Bitmap</param>
/// <param name="applyRect">Rectangle</param>
/// <param name="clone">bool specifying if the bitmap needs to be cloned</param>
public BitmapBuffer(Bitmap sourceBmp, Rectangle applyRect, bool clone)
{
this.clone = clone;
Rectangle sourceRect = new Rectangle(applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height);
Rectangle bitmapRect = new Rectangle(0,0, sourceBmp.Width, sourceBmp.Height);
if(sourceRect.Equals(Rectangle.Empty)) {
sourceRect = bitmapRect;
} else {
sourceRect.Intersect(bitmapRect);
}
// Does the rect have any pixels?
if (sourceRect.Height <= 0 || sourceRect.Width <= 0) {
return;
}
if (SupportsPixelFormat(sourceBmp)) {
if (clone) {
// Create copy with supported format
this.bitmap = sourceBmp.Clone(sourceRect, sourceBmp.PixelFormat);
} else {
this.bitmap = sourceBmp;
}
} else {
// We can only clone, as we don't support the pixel format!
if (!clone) {
throw new ArgumentException("Not supported pixel format: " + sourceBmp.PixelFormat);
}
// When sourceRect is the whole bitmap there is a GDI+ bug in Clone
// Clone will than return the same PixelFormat as the source
// a quick workaround is using new Bitmap which uses a default of Format32bppArgb
if (sourceRect.Equals(bitmapRect)) {
this.bitmap = new Bitmap(sourceBmp);
} else {
this.bitmap = sourceBmp.Clone(sourceRect, PixelFormat.Format32bppArgb);
}
}
// Set "this" rect to location 0,0
// as the Cloned Bitmap is only the part we want to work with
this.rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
}
示例14: RenderDiagramImplementation
private void RenderDiagramImplementation(Rectangle renderRectangle)
{
if (! Suspended)
{
if (! renderRectangle.Equals(mRenderRectangle)) DisposeGraphicsStateBitmap();
Graphics graphics = CreateGraphics(renderRectangle);
if (graphics==null) return;
OnPreRender(graphics);
//Render the elements if the renderer isnt locked
if (!mLocked) RenderDiagramElements(graphics);
//Render the decorations
if (mDrawDecorations) RenderDecorations(graphics, renderRectangle);
OnPostRender(graphics);
graphics.Dispose();
}
}
示例15: Apply
public unsafe override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle applyRect, RenderMode renderMode)
{
Rectangle sourceRect = new Rectangle(applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height);
Rectangle bitmapRect = new Rectangle(0,0, applyBitmap.Width, applyBitmap.Height);
if(sourceRect.Equals(Rectangle.Empty)) {
sourceRect = bitmapRect;
} else {
sourceRect.Intersect(bitmapRect);
}
// Does the rect have any pixels?
if (sourceRect.Height <= 0 || sourceRect.Width <= 0) {
return;
}
int blurRadius = GetFieldValueAsInt(FieldType.BLUR_RADIUS);
// Calculate new sourceRect to include the matrix size if possible
int leftOffset = Math.Min(sourceRect.X, blurRadius);
int rightOffset = Math.Min(applyBitmap.Width - (sourceRect.X + sourceRect.Width), blurRadius);
int topOffset = Math.Min(sourceRect.Y, blurRadius);
int bottomOffset = Math.Min(applyBitmap.Height - (sourceRect.Y + sourceRect.Height), blurRadius);
LOG.Debug(String.Format("Offsets: {0},{1},{2},{3}", leftOffset, rightOffset, topOffset, bottomOffset));
LOG.Debug(String.Format("SourceRect before: {0},{1},{2},{3}", sourceRect.X, sourceRect.Width, sourceRect.Y, sourceRect.Height));
sourceRect.X -= leftOffset;
sourceRect.Width += leftOffset + rightOffset;
sourceRect.Y -= topOffset;
sourceRect.Height += topOffset + bottomOffset;
LOG.Debug(String.Format("SourceRect after: {0},{1},{2},{3}", sourceRect.X, sourceRect.Width, sourceRect.Y, sourceRect.Height));
// Make a copy of the applyBitmap for reading
using (Bitmap sourceBitmap = applyBitmap.Clone(sourceRect, applyBitmap.PixelFormat)) {
ApplySmooth(sourceBitmap, applyBitmap, sourceRect, blurRadius);
}
}